I am integrating Payfort payment gateway in my android application. I am using FORT SDKv1.2.
In the post url for creating token, I am getting error "signature mismatch" always.
Can anybody tell me which signature is to be used?
url - https://sbpaymentservices.payfort.com/FortAPI/paymentApi
Let me guide you step by step:
NOTE: The following is an example for the Merchant Page 2.0 request signature generation:
Step 1: Add these variables on top of your file
private final static String KEY_MERCHANT_IDENTIFIER = "merchant_identifier";
private final static String KEY_SERVICE_COMMAND = "service_command";
private final static String KEY_LANGUAGE = "language";
private final static String KEY_ACCESS_CODE = "access_code";
private final static String KEY_MERCHANT_REFERENCE = "merchant_reference";
private final static String MERCHANT_IDENTIFIER = "YOUR_MERCHANT_IDENTIFIER";
private final static String ACCESS_CODE = "YOUR_ACCESS_CODE";
private final static String SHA_TYPE = "SHA-256";
private final static String SHA_REQUEST_PHRASE = "YOUR_SHA_REQUEST_PHRASE ";
private final static String LANGUAGE_TYPE = "en";
Make sure you are using your given MERCHANT_IDENTIFIER, ACCESS_CODE and SHA_REQUEST_PHRASE by Payfort.
Step 2: Create a string
String concatenatedString = SHA_REQUEST_PHRASE +
KEY_ACCESS_CODE + "=" + ACCESS_CODE +
KEY_LANGUAGE + "=" + LANGUAGE_TYPE +
KEY_MERCHANT_IDENTIFIER + "=" + MERCHANT_IDENTIFIER +
KEY_MERCHANT_REFERENCE + "=" + YOUR_MERCHANT_REFERENCE +
KEY_SERVICE_COMMAND + "=" + "TOKENIZATION" +
SHA_REQUEST_PHRASE;
Here YOUR_MERCHANT_REFERENCE is your unique merchant reference. It should be unique for every request
Step 3: Create a function to generate SHA-256 type signature from your
concatenatedString in Step 2
private String createSignature(String s) {
try {
// Create MD5 Hash
MessageDigest digest = MessageDigest.getInstance(SHA_TYPE);
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
return String.format("%0" + (messageDigest.length * 2) + 'x', new BigInteger(1, messageDigest));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
Finally
Call the createSignature function by passing your concatenatedString in Step 2.
String signature = createSignature(concatenatedString);
Change 'merchant_reference' value to one you didn't use before. It should be unique. I had the same trouble and it was fixed using it.
Sort your keys in array alphabetically, add before and after the secret phrases and then encrypt the string using your algorythm.
After it, you can use it in your requests.
I have faced same problem and found there is problem in algorithm i hvae used while generating signature. So plz check sequence of parameters while generating signature. and check for algorithm which u have setup in account and use same algorithm while generating signature
also make sure that the merchant reference is alphanumric and if you want to add special chars you can only add . _ -
Here you can find how to generate signature.
I was facing this signature mismatch error due to concatenating wrong SHA Request Phrase to the start and end of the signature.
I have faced same problem and found there is problem in integration settings.Just login into your payfort account and goto payment integration settings then your merchant reference id place check
SHA Type is SHA-256 and SHA Response Parse ,SHA Request Parse will same text.This same text added to your accesscode and sdk-token in the source code parameters.Please check below image once.
Use this code
String concatenatedString = SHA_REQUEST_PHRASE +
KEY_ACCESS_CODE + "=" + ACCESS_CODE +
KEY_DEVICE_ID + "=" + device_id +
KEY_LANGUAGE + "=" + LANGUAGE_TYPE +
KEY_MERCHANT_IDENTIFIER + "=" + MERCHANT_IDENTIFIER +
KEY_SERVICE_COMMAND + "=" + SDK_TOKEN +
SHA_REQUEST_PHRASE;
Then, pass this concatenated string in below method,
private static String getSignatureSHA256(String s) {
try {
// Create MD5 Hash
MessageDigest digest = MessageDigest.getInstance(SHA_TYPE);
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
return String.format("%0" + (messageDigest.length * 2) + 'x', new BigInteger(1, messageDigest));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
Use below code to get Signature,
String signature = getSignatureSHA256(concatenatedString);
Happy Coding :)
Related
I am trying to use the Rest Api with temporary credentials to download images stored in an S3 bucket in AWS from my Android App. I need to use the rest API instead of the TransferUtility method included in the Android AWS SDK, because I want to use an image downloader for better performance. According to the official AWS docs, I need to add an Authorization header to the HTTP Get request, that is conform like this:
Authorization = "AWS" + " " + AWSAccessKeyId + ":" + Signature;
Signature = Base64( HMAC-SHA1( YourSecretAccessKeyID, UTF-8-Encoding-Of( StringToSign ) ) );
StringToSign = HTTP-Verb + "\n" +
Content-MD5 + "\n" +
Content-Type + "\n" +
Date + "\n" +
CanonicalizedAmzHeaders +
CanonicalizedResource;
https://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html#RESTAuthenticationConstructingCanonicalizedAmzHeaders
So, I obtain the Authorization header like this:
public String AuthorizationHeader (String dirToImageInBucket) throws UnsupportedEncodingException {
final AWSMobileClient mobileClient = AWSMobileClient.defaultMobileClient();
IdentityManager iM = mobileClient.getIdentityManager();
AWSCredentialsProvider sCredProvider= iM.getCredentialsProvider();
String secretKey = sCredProvider.getCredentials().getAWSSecretKey();
String awsAccessKeyId = sCredProvider.getCredentials().getAWSAccessKeyId();
Mac hmac = null;
hmac = Mac.getInstance("HmacSHA1");
hmac.init(new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA1"));
Date dateT = new Date();
#SuppressLint("SimpleDateFormat") DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
String date = dateFormat.format(dateT);
String token = "x-amz-security-token:" + Login_Related.geToken(activity) +"\nx-amz-date:" +date+"\n";
String stringToSign = "GET" + "\n\n\n" + date + "\n" + token + "/" + dirToImageInBucket;
String signature = ( Base64.encodeToString(hmac.doFinal(stringToSign.getBytes("UTF-8")), Base64.DEFAULT)).replaceAll("\n", "");
return "AWS" + " " + awsAccessKeyId + ":" + signature;
}
Then I add the "Authorization" header returned by the previous method to the HTTP GET request, and also I include the headers x-amz-date and x-amz-security-token in the request (with the values of date and temporary access token respectively). I am currently testing the request on Postman to test if I can download the image by adding the mentioned headers to GET request of the image URL, and every time I send it, I get the response :
<Error>
<Code>InvalidToken</Code>
<Message>The provided token is malformed or otherwise invalid.</Message>
<Token-0>eyJraWQiOiJ4TFYxcVZiNG1IY3IrSWUxS....
I am sure I am using the right token, since the others http requests in my app are working properly with that token. Can anyone please help me realize what am I missing or doing wrong? Thanks.
Edited to include the token method:
static public String geToken(Activity act) {
AWSMobileClient.initializeMobileClientIfNecessary(act.getApplicationContext());
final AWSMobileClient mobileClient = AWSMobileClient.defaultMobileClient();
IdentityManager iM = mobileClient.getIdentityManager();
IdentityProvider iP = iM.getCurrentIdentityProvider();
token = iP.refreshToken();
System.out.println("x-amz-security-token check this token: " + token);
return token;
}
I have integrated payu into my android app through official docs at
https://www.payumoney.com/dev-guide/mobilecheckout/android.html#prereq .
The problem i'm facing is that my code works perfectly with test credentials, and fails when i use credentials of my live account that i want to integrate in the app.
public void makePayment(View view) {
String phone = "8882434664";
String productName = "product_name";
String firstName = "piyush";
String txnId = "0nf7" + System.currentTimeMillis();
String email = "piyush.jain#payu.in";
String sUrl = "https://test.payumoney.com/mobileapp/payumoney/success.php";
String fUrl = "https://test.payumoney.com/mobileapp/payumoney/failure.php";
String udf1 = "";
String udf2 = "";
String udf3 = "";
String udf4 = "";
String udf5 = "";
boolean isDebug = true;
String key = "2fcU3pmI";
String merchantId = "4947182";// These credentials are from https://test.payumoney.com/
String salt = "BxA24L2F7Z"; // THIS WORKS
/* String key = "yX8OvWy1"; //These credentials are from https://www.payumoney.com/
String merchantId = "5826688"; //THIS DOESN'T WORK
String salt = "0vciMJBbaa"; //ERROR: "some error occurred, Try again"
*/
PayUmoneySdkInitilizer.PaymentParam.Builder builder = new PayUmoneySdkInitilizer.PaymentParam.Builder();
builder.setAmount(getAmount())
.setTnxId(txnId)
.setPhone(phone)
.setProductName(productName)
.setFirstName(firstName)
.setEmail(email)
.setsUrl(sUrl)
.setfUrl(fUrl)
.setUdf1(udf1)
.setUdf2(udf2)
.setUdf3(udf3)
.setUdf4(udf4)
.setUdf5(udf5)
.setIsDebug(isDebug) //Also can someone clarify if this should be true/false for live mode
.setKey(key)
.setMerchantId(merchantId);
PayUmoneySdkInitilizer.PaymentParam paymentParam = builder.build();
String hash = hashCal(key + "|" + txnId + "|" + getAmount() + "|" + productName + "|"
+ firstName + "|" + email + "|" + udf1 + "|" + udf2 + "|" + udf3 + "|" + udf4 + "|" + udf5 + "|" + salt);
Log.d("app_activity123", hash);
paymentParam.setMerchantHash(hash);
PayUmoneySdkInitilizer.startPaymentActivityForResult(MyActivity.this, paymentParam);
}
Extra Info: Test credentials weren't working initially. I had to contact the payu support team to activate the account after which the code was working fine. My employer said he has activated the live account so i don't know what is the issue here.
There are no other issues like mine here, the closest one is here PayuMoney Integration in Android : Some error occured! Try again and it is unanswered.
setIsDebug(boolean) you need to pass false as parameter in this method to use live payment and true when testing in live mode.
I've set it to false and used Real Merchant id,salt and key and it worked, no errors.
Hope this helps someone.
Debug into PayUmoneyActivity
ErrorResponse contains the actual error.
It may be hash mismatch or wrong key.
#override
public void onFailureResponse(ErrorResponse response, String tag) {
mProgressDialog.dismiss();
Toast.makeText(context, "Some error occured",
Toast.LENGTH_SHORT).show();
finish();
}
this method in PayUmoneyActivity does not show error from errorresponse. just the general error. which is very problematic to debug.
I think your problem is in the line
'PayUmoneySdkInitilizer.startPaymentActivityForResult(MyActivity.this, paymentParam);'.
The official document states that you have to start transaction by using
'PayUmoneyFlowManager.startPayUMoneyFlow(paymentParam,this, R.style.AppTheme_default, false);'
Now I simplify the problem.
I try to directly copy and paste the query to confrim it use %3D instead of '='
var xhrSNS = Ti.Network.createHTTPClient({
onload :function(e) {
Ti.API.info("test Post query:" + JSON.stringify(e));
Ti.API.info(this.responseText);
},
onerror : function(e){
Ti.API.debug("test Create PlatForm Endpoint registerPush error:" + e.error);
Ti.API.info(this.responseText);
}
});
getUrl = "http://sns.ap-northeast-1.amazonaws.com?AWSAccessKeyId=AAAAAAAAAAAAAAA&Action=CreatePlatformEndpoint&PlatformApplicationArn=arn%3Aaws%3Asns%3Aap-northeast-1%3A776188326341%3Aapp%2FGCM%2Fmyapp&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-03T15%3A05%3A51.465Z&Token=APA91bEiaB-902cRmwwgCwoqi2jRIJzzTIZNB7XduELuBKit_WF29tN5twrVW5t1BHpj07ARgwjzoc-I5xVur5K6I6ZQcnoErguUyi-VBHvuI5eY9HS4jq1J6KbIC05Etoe8indjpY9X&Version=2010-03-31&Signature=DzxQpP%2BcALS91C53eia6ZkBhxg3lQ32ctqiEmqKwwLA%3D";
xhrSNS.open('GET',getUrl);
xhrSNS.send();
Please see the last letter of getUrl, it surely use '%3D'.
But return is the same.
It makes a complaint that sentence include '=' delimiter.
[DEBUG] test Create PlatForm Endpoint registerPush error:400 : Bad Request
[INFO] <ErrorResponse xmlns="http://webservices.amazon.com/AWSFault/2005-15-09">
[INFO] <Error>
[INFO] <Type>Sender</Type>
[INFO] <Code>MalformedQueryString</Code>
[INFO] <Message>AWSAccessKeyId=AAAAAAAAAAAAAAA&Action=CreatePlatformEndpoint&PlatformApplicationArn=arn%3Aaws%3Asns%3Aap-northeast-1%3A776188326341%3Aapp%2FGCM%2Fmyapp&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-03T15%3A05%3A51.465Z&Token=APA91bEiaB-902cRmwwgCwoqi2jRIJzzTIZNB7XduELuBKit_WF29tN5twrVW5t1BHpj07ARgwjzoc-I5xVur5K6I6ZQcnoErguUyi-VBHvuI5eY9HS4jq1J6KbIC05Etoe8indjpY9X&Version=2010-03-31&Signature=DzxQpP%2BcALS91C53eia6ZkBhxg3lQ32ctqiEmqKwwLA= is not valid; the value of a query string parameter may not contain a '=' delimiter</Message>
-----------------------------adding until here-----------------
I am using Amazon SNS API
I made url like this it works well on browser.
http://sns.ap-northeast-1.amazonaws.com?AWSAccessKeyId=AAAAAAAAAAAAA&Action=CreatePlatformEndpoint&PlatformApplicationArn=arn%3Aaws%3Asns%3Aap-northeast-1%3A776188326341%3Aapp%2FGCM%2Fmyapp&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-01T21%3A06%3A29.861Z&Token=APA91bEiaB-902cRmwwgCwoqi2jRIJzzTIZNB7XduELuBKit_WF29tN5twrVW5t1BHpj07ARgwjzoc-I5xVur5K6I6ZQcnoErguUyi-VBHvuI5eY9HS4jq1J6KbIC05Etoe8indjpY9X&Version=2010-03-31&Signature=Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIKKekAI%3D
However if I try from Android.
This returns 400 bad request.
<ErrorResponse xmlns="http://webservices.amazon.com/AWSFault/2005-15-09">
<Error>
<Type>Sender</Type>
<Code>MalformedQueryString</Code>
<Message>AWSAccessKeyId=AAAAAAAAAAAAA&Action=CreatePlatformEndpoint&PlatformApplicationArn=arn%3Aaws%3Asns%3Aap-northeast-1%3A776188326341%3Aapp%2FGCM%2Fmyapp&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-01T21%3A06%3A29.861Z&Token=APA91bEiaB-902cRmwwgCwoqi2jRIJzzTIZNB7XduELuBKit_WF29tN5twrVW5t1BHpj07ARgwjzoc-I5xVur5K6I6ZQcnoErguUyi-VBHvuI5eY9HS4jq1J6KbIC05Etoe8indjpY9X&Version=2010-03-31&Signature=Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIWUekAI=
is not valid; the value of a query string parameter may not contain a '=' delimiter</Message>
</Error>
<RequestId>5b40d988-af34-577a-8839-96f04a217dec</RequestId>
</ErrorResponse>
I think
the value of a query string parameter may not contain a '=' delimiter
is the cause of problem though, I cant figure out how to fix it.
The same code works on iPhone.
it doesn't work only from android.
I made URL strings from this function
var array = {
PlatformApplicationArn : Ti.App.global.androidArn
};
awsObj = getSignature("CreatePlatformEndpoint",date,awsUrl,event.registrationId,array);
var getUrl = "http://" + awsUrl + '?' + awsObj.str_para + "&Signature=" + awsObj.encodedString;
Ti.API.info('GETurl :' + getUrl);
xhrSNS.open('GET',getUrl);
function getSignature(action,date,awsUrl,token,array){
Ti.include('/jssha/jssha256.js');
var base = {
Action:action,
AWSAccessKeyId : Ti.App.global.awsAccessKey,
SignatureMethod : "HmacSHA256",
SignatureVersion :2,
Token: token,
Timestamp : date,
Version : "2010-03-31",
};
para = arrayMerge(array,base);
var para_array = [];
for(var pname in para){
para_array.push(pname + "=" + encodeURIComponent(para[pname]));
}
para_array.sort();
var str_para = para_array.join('&');
var str_signature = "GET" + "\n" + awsUrl + "\n" + "/" + "\n" + str_para;
console.log("str_signature:" + str_signature);
HMAC_SHA256_init(Ti.App.global.awsSecretKey);
HMAC_SHA256_write(str_signature);
var array_hash = HMAC_SHA256_finalize();
var str_hash = "";
for (var i = 0; i < array_hash.length; i++) {
str_hash += String.fromCharCode(array_hash[i]);
}
var awsObj = new Object();
awsObj.encodedString = encodeURIComponent(base64encode(str_hash));
Ti.API.info("awsObj.encodedString:" + awsObj.encodedString); // I have confirmed encodedString is correct here.
awsObj.str_para = str_para;
return awsObj;
}
URL in browser: Signature=Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIKKekAI%3D
URL in Android: Signature=Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIWUekAI=
Now I simplify the problem.
I try to directly copy and paste the query to confrim it use %3D instead of '='
var xhrSNS = Ti.Network.createHTTPClient({
onload :function(e) {
Ti.API.info("test Post query:" + JSON.stringify(e));
Ti.API.info(this.responseText);
},
onerror : function(e){
Ti.API.debug("test Create PlatForm Endpoint registerPush error:" + e.error);
Ti.API.info(this.responseText);
}
});
getUrl = "http://sns.ap-northeast-1.amazonaws.com?AWSAccessKeyId=AAAAAAAAAAAAAAA&Action=CreatePlatformEndpoint&PlatformApplicationArn=arn%3Aaws%3Asns%3Aap-northeast-1%3A776188326341%3Aapp%2FGCM%2Fmyapp&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-03T15%3A05%3A51.465Z&Token=APA91bEiaB-902cRmwwgCwoqi2jRIJzzTIZNB7XduELuBKit_WF29tN5twrVW5t1BHpj07ARgwjzoc-I5xVur5K6I6ZQcnoErguUyi-VBHvuI5eY9HS4jq1J6KbIC05Etoe8indjpY9X&Version=2010-03-31&Signature=DzxQpP%2BcALS91C53eia6ZkBhxg3lQ32ctqiEmqKwwLA%3D";
xhrSNS.open('GET',getUrl);
xhrSNS.send();
Please see the last letter of getUrl, it surely use '%3D'.
But return is the same.
It makes a complaint that sentence include '=' delimiter.
[DEBUG] test Create PlatForm Endpoint registerPush error:400 : Bad Request
[INFO] <ErrorResponse xmlns="http://webservices.amazon.com/AWSFault/2005-15-09">
[INFO] <Error>
[INFO] <Type>Sender</Type>
[INFO] <Code>MalformedQueryString</Code>
[INFO] <Message>AWSAccessKeyId=AAAAAAAAAAAAAAA&Action=CreatePlatformEndpoint&PlatformApplicationArn=arn%3Aaws%3Asns%3Aap-northeast-1%3A776188326341%3Aapp%2FGCM%2Fmyapp&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-03T15%3A05%3A51.465Z&Token=APA91bEiaB-902cRmwwgCwoqi2jRIJzzTIZNB7XduELuBKit_WF29tN5twrVW5t1BHpj07ARgwjzoc-I5xVur5K6I6ZQcnoErguUyi-VBHvuI5eY9HS4jq1J6KbIC05Etoe8indjpY9X&Version=2010-03-31&Signature=DzxQpP%2BcALS91C53eia6ZkBhxg3lQ32ctqiEmqKwwLA= is not valid; the value of a query string parameter may not contain a '=' delimiter</Message>
-----------------------------adding until here-----------------
I am using Amazon SNS API
I made url like this it works well on browser.
http://sns.ap-northeast-1.amazonaws.com?AWSAccessKeyId=AAAAAAAAAAAAA&Action=CreatePlatformEndpoint&PlatformApplicationArn=arn%3Aaws%3Asns%3Aap-northeast-1%3A776188326341%3Aapp%2FGCM%2Fmyapp&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-01T21%3A06%3A29.861Z&Token=APA91bEiaB-902cRmwwgCwoqi2jRIJzzTIZNB7XduELuBKit_WF29tN5twrVW5t1BHpj07ARgwjzoc-I5xVur5K6I6ZQcnoErguUyi-VBHvuI5eY9HS4jq1J6KbIC05Etoe8indjpY9X&Version=2010-03-31&Signature=Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIKKekAI%3D
However if I try from Android.
This returns 400 bad request.
<ErrorResponse xmlns="http://webservices.amazon.com/AWSFault/2005-15-09">
<Error>
<Type>Sender</Type>
<Code>MalformedQueryString</Code>
<Message>AWSAccessKeyId=AAAAAAAAAAAAA&Action=CreatePlatformEndpoint&PlatformApplicationArn=arn%3Aaws%3Asns%3Aap-northeast-1%3A776188326341%3Aapp%2FGCM%2Fmyapp&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-01T21%3A06%3A29.861Z&Token=APA91bEiaB-902cRmwwgCwoqi2jRIJzzTIZNB7XduELuBKit_WF29tN5twrVW5t1BHpj07ARgwjzoc-I5xVur5K6I6ZQcnoErguUyi-VBHvuI5eY9HS4jq1J6KbIC05Etoe8indjpY9X&Version=2010-03-31&Signature=Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIWUekAI=
is not valid; the value of a query string parameter may not contain a '=' delimiter</Message>
</Error>
<RequestId>5b40d988-af34-577a-8839-96f04a217dec</RequestId>
</ErrorResponse>
I think
the value of a query string parameter may not contain a '=' delimiter
is the cause of problem though, I cant figure out how to fix it.
The same code works on iPhone.
it doesn't work only from android.
I made URL strings from this function
var array = {
PlatformApplicationArn : Ti.App.global.androidArn
};
awsObj = getSignature("CreatePlatformEndpoint",date,awsUrl,event.registrationId,array);
var getUrl = "http://" + awsUrl + '?' + awsObj.str_para + "&Signature=" + awsObj.encodedString;
Ti.API.info('GETurl :' + getUrl);
xhrSNS.open('GET',getUrl);
function getSignature(action,date,awsUrl,token,array){
Ti.include('/jssha/jssha256.js');
var base = {
Action:action,
AWSAccessKeyId : Ti.App.global.awsAccessKey,
SignatureMethod : "HmacSHA256",
SignatureVersion :2,
Token: token,
Timestamp : date,
Version : "2010-03-31",
};
para = arrayMerge(array,base);
var para_array = [];
for(var pname in para){
para_array.push(pname + "=" + encodeURIComponent(para[pname]));
}
para_array.sort();
var str_para = para_array.join('&');
var str_signature = "GET" + "\n" + awsUrl + "\n" + "/" + "\n" + str_para;
console.log("str_signature:" + str_signature);
HMAC_SHA256_init(Ti.App.global.awsSecretKey);
HMAC_SHA256_write(str_signature);
var array_hash = HMAC_SHA256_finalize();
var str_hash = "";
for (var i = 0; i < array_hash.length; i++) {
str_hash += String.fromCharCode(array_hash[i]);
}
var awsObj = new Object();
awsObj.encodedString = encodeURIComponent(base64encode(str_hash));
Ti.API.info("awsObj.encodedString:" + awsObj.encodedString); // I have confirmed encodedString is correct here.
awsObj.str_para = str_para;
return awsObj;
}
URL in browser: Signature=Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIKKekAI%3D
URL in Android: Signature=Dt9tXa0Rjl%2Ff6YxZ4JaPfsm%2BT%2BMX03gS712nIWUekAI=
resultString is the parameter I get from sqlite
resultString = result.getString(result.getColumnIndex(1));
I want to compare ignore case with user input , following is the code I have use. But it doesn't work.
For example, in database, I store a username "George"
When I login, I have to type exactly "George"."george" doesn't work.
Here is my code to compare.
if (userName.equalsIgnoreCase(resultString)) {
return true;
}
What might be the problem?
Please try following code,
if (userName.trim().equalsIgnoreCase(resultString.trim()))
{
return true;
}
Your code should work if the only difference is the case. I suspect you have leading or trailing spaces. Try the following:
if (userName.trim().equalsIgnoreCase(resultString.trim())) {
return true;
}
I was panic and didn't try the to print out the result.The problem was my query statement.
String whereClause = DatabaseHelper.USER_COL + " name =?";
The resultString is always empty unless input is the same as data.
To fix it I follow instruction in this post
sqlite LIKE problem in android
String whereClause = DatabaseHelper.USER_COL + " LIKE ?";
userName = userName+"%"
int Num;
String answer = et_q7.getText().toString();
String right_answer = "Air Pollution";
String right_answer2 = "Air";
if (answer.trim().equalsIgnoreCase(right_answer.trim()) || answer.trim().equalsIgnoreCase(right_answer2.trim())) {
Num = 1;
} else {
Num = 0;
}