CCAvenue does not provide integration kit for Salesforce Apex language. They provide Asp.net, Java, NodeJS, iOS, Android, Windows.
How do we encrypt data and make request for CCAvenue payment gateway?
After lots of struggle we managed to get encrypt and dcrypt data in salesforce apex.
Here is Encryption:
/*
This PLAIN_TEXT is your data collected from your apex form. Few values are required and lots of values are optional. Please read document provided by ccavenue.
*/
String PLAIN_TEXT = 'tid=XXXX&merchant_id=XXXX&order_id=XXXX&amount=XX¤cy=INR&redirect_url=XXXX&cancel_url=XXXX&language=EN&billing_name=XXXX&billing_address=XXXX&billing_city=XXXX&billing_state=XX&billing_zip=XXXX&billing_country=XXXX&billing_tel=XXXX&billing_email=XXXX&delivery_name=XXXX&delivery_address=XXXX&delivery_city=XXXX&delivery_state=XXXX&delivery_zip=XXXX&delivery_country=XXXX&delivery_tel=XXXX&merchant_param1=XXXX&merchant_param2=XXXX&merchant_param3=XXXX&merchant_param4=XXXX&merchant_param5=XXXX&promo_code=&customer_identifier=&';
//WORKING_KEY is key provided by CCAvenue when you register as Merchant.
Blob cryptoKey = Blob.valueOf('WORKING_KEY');
Blob hash = Crypto.generateDigest('MD5', cryptoKey );
Blob data = Blob.valueOf(PLAIN_TEXT);
Blob encryptedData = Crypto.encryptWithManagedIV('AES128', hash , data);
String encRequest = EncodingUtil.convertToHex(encryptedData );
/*Pass this encRequest with access_code to the https://secure.ccavenue.com/transaction/transaction.do?command=initiateTransaction using visualforce FORM
*/
Here is Decryption:
Blob cryptoKey = Blob.valueOf('WORKING_KEY');
Blob hash = Crypto.generateDigest('MD5', cryptoKey);
Blob data = EncodingUtil.convertFromHex('ENC_RESPONSE'); //Received from ccAvenue response
Blob decryptedText = Crypto.decryptWithManagedIV('AES128', hash, data);
String PLAIN_TEXT = decryptedText.toString();
Related
I have written the following code to generate a json web token -
byte[] secret = Base64.getDecoder().decode("XXX");
public String generateJsonWebToken(String strUsernameForTokenCreation) {
Instant now = Instant.now();
String jwt = Jwts.builder()
.setSubject(strUsernameForTokenCreation)
.setIssuedAt(Date.from(now))
//set expiration time from now 10 minute
.setExpiration(Date.from(now.plus(10,ChronoUnit.MINUTES)))
//use the secret key
.signWith(Keys.hmacShaKeyFor(secret))
//generate jwt string
.compact();
System.out.println(jwt);
return jwt;
}
Which is working fine .But ,I need to add that json web token in a confirmation link which needs to be sent to registered e-mail id. I am finding it difficult to create a confirmation link including a jsonweb token which we insert in header section of postman in authentication bearer.How can a link be generated with json web token ? Also , how can it be utilized in a post method in reactJS later on ?
I am trying to apply client side encryption, for this using AWS KMS I created Asymmetric key. I downloaded the public key and then from the frontend (I am using react). I am using the following function to encrypt the data
function encryptMessage(message, publicKey) {
const jsEncrypt = new JSEncrypt();
jsEncrypt.setPublicKey(publicKey);
return jsEncrypt.encrypt(message);
}
I later encode this in base64 before sending it,
The key spec is RSA_2048
And I want to use RSAES_OAEP_SHA_256 as my encryption algorithm.
Following is the backend, written in python to decrypt the message:
client = boto3.client('kms')
res = base64.b64decode(blob)
print(res)
response = client.decrypt(
CiphertextBlob=res,
KeyId='xxxxxxxxxxxxxxxxxxxxx',
EncryptionAlgorithm='RSAES_OAEP_SHA_256'
)
print(response)
I am unable to send a proper encrypted message so that it can be decrypted from backend.
How do I set EncryptionAlgorithm on react?
I am actually trying to implement text-to-speech conversion in Salesforce by hitting a third-party api. When i send the request through Postman, i get back the proper response in .wav format. However, I'm not being able to handle this reponse programatically in salesforce end, as I am not able to store the response in any audio object.
Any assistance would be greatly appreciated.
Thanks in advance.
Abhishek.
Not 100% sure of what your trying to do but it would look something like this assuming you built your object correctly
ResponseObject result = new ResponseObject();
result = (InnerClasses.ResponseObject)JSON.deserialize(json, InnerClasses.ResponseObject.class);
This is supported by IBM's Watson Salesforce SDK, available here
The functional tests for Watson's text-to-speech services can be found here refer to the method
testSynthesize(String username, String password, String customizationId)
The audio file returned as part of the response could be saved as an attachment in Salesforce by simply creating it from the IBMWatsonFile like on this example,
IBMWatsonFile resp = textToSpeech.synthesize(options);
Attachment attachment = new Attachment();
attachment.Body = resp.body();
attachment.Name = resp.name();
attachment.ParentId = '<your salesforce parent id>';
insert attachment;
This code uses basically the method getBodyAsBlob() available from the HttpResponse class
before using this approach, please consider the governor limits enforced by Salesforce on any APEX callout, refer to the Maximum size of callout request or response documented here
I'm working with Google Cloud Storage in AppEngine and I'm attempting to use a POST form to upload a file to GCS. The problem I'm having is with the steps needed to sign the policy document. I can easily fetch the client_secret, which is a String from the client_secrets.json that the API Console gave me. however, in order to create a signature, I need to convert that string into a PrivateKey object. Here's what my code looks like:
//create the policy document and encode it
String policyDocument = ... //omitted for brevity
String encodedPolicy = Base64.encodeString(policyDocument);
//sign using SHA256 with RSA
String secretKey = ... //I fetch this from client_secrets.json
Signature sig = Signature.getInstance("SHA256withRSA");
sig.initSign(secretKey); //THIS IS THE PROBLEM!
sig.update(encodedPolicy.getBytes("UTF-8"));
String signature = new String(Base64.encode(sig.sign()));
//put the values in the request attributes so we can fetch them from a JSP
req.setAttribute("policy", encodedPolicy);
req.setAttribute("signature", signature);
As noted above, my problem is in the line
sig.initSign(secretKey); //THIS IS THE PROBLEM!
secretKey is a String. Signature.initSign() expects a PrivateKey, or one of its descendant objects. How do I convert the string in the client_secrets.json into a PrivateKey (or derived) object that I can pass Signature.initSign?
Any help would be greatly appreciated. Thanks
OK, here's where I am right now. I tried the suggestions below, and all of the documentation is urging me to use the client_secret in the client_secrets.json file downloaded from the Google API console, not the service account. And besides, I'm trying to construct an example of a user's upload, not a service account.
I found the following code on another page:
public static String signPolicyDocument(String policyDocument, String secret) {
try {
Mac mac = Mac.getInstance("HmacSHA256");
byte[] secretBytes = secret.getBytes();
SecretKeySpec signingKey = new SecretKeySpec(secretBytes, "HmacSHA256");
mac.init(signingKey);
byte[] signedSecretBytes = mac.doFinal(policyDocument.getBytes());
return new String(Base64.encode(signedSecretBytes));
} catch (InvalidKeyException e) {
throw new RuntimeException(e);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e);
}
And it gets me all the way through the process...until I submit the resulting form. Then I get the following response:
The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.
What signing method is it looking for?
Here's what I think you need to do:
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
sig.initSign(privateKey);
The keyBytes variable should contain a byte[] array with your service account key file in it.
The final answer to this problem is like the conclusion of Wargames. As WOPR said, "A strange game...the only way to win is not to play." Avoid signing and policy document and all that crap and use the blobstore.
(See this: https://developers.google.com/appengine/docs/java/blobstore/overview#using-blobstore-with-gcs)
It's very easy to implement; when you create your temporary blobstore upload URL like so:
//open the blobstore service and create the upload url
BlobstoreService bs = BlobstoreServiceFactory.getBlobstoreService();
String uploadUrl = bs.createUploadUrl("/display",
UploadOptions.Builder.withGoogleStorageBucketName(bucket));
The downside to this approach is the object name will be a string of characters you don't recognize. You can open the blobstore viewer and see your object by file name in the blobstore, but in GCS its object name will be gobbledygook. (A hash, maybe? A randomly assigned ID)?
To upload a file to GCS from Appengine you can use the blobstore Api. Follow the steps described in Using Blobstore with GCS. The advantage is that you don't have to worry about keys and the code is much simpler.
I have looked everywhere, but have not found a solution for this issue. I am trying to update a field in SalesForce for a lead. The way I have it sending right now is:
string postData = string.Format("Data I am Sending");
//send data
var data = Encoding.UTF8.GetBytes(postData);
try {
WebRequest request = WebRequest.Create("https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
Stream newStream = request.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
}
catch { }
instead of it creating a new entry, I want it to update the other fields of the lead where the email address matches the data I send it. So something like:
postData = "oid=myOid&email=" + emailIWantToMatch.Text + "...";
Is this possible or will I have to use the apex api?
The Web2Lead feature can only create new leads, not update existing ones. To do updates you'll need to use either the soap or rest API
Or you can create a Force.com Site Web2Lead page (Creating a Web-to-Lead Form for Your Force.com Site) and have your controller the logic to insert/update based on email-id.