+ Start a Discussion
karimulla testingkarimulla testing 

ecrption function ,validation

(Encrpting with key "1234567890123456" it is getting encrpted):
Blob key = Blob.valueOf('1234567890123456');  //WITH 16BYTES
String myStringToEncrypt = 'This is my String....'
Blob myBlobData = Blob.valueOf(myStringToEncrypt)
Blob myEncryptedString = Crypto.encryptWithManagedIV('AES256', key, myBlobData)

(Encrpting with key "INDIA" it is  not getting encrpted)  :
SHOWING ERROR: 
 Invalid private key. Must be 16 bytes.

Blob key = Blob.valueOf('INDIA'); //
String myStringToEncrypt = 'This is my String....'
Blob myBlobData = Blob.valueOf(myStringToEncrypt)
Blob myEncryptedString = Crypto.encryptWithManagedIV('AES256', key, myBlobData)

/// I KNOW THAT IT SHOULD BE 16 BYTES REQUIRED
//////bt in .net application they used the key "INDIA" and encrpted with 'AES256'.. need samekey "INDIA"   in salesforce ...MAY I GET THE SOLUTION
Raj VakatiRaj Vakati

in sfdc , The length of privateKey must match the specified algorithm: 128 bits, 192 bits, or 256 bits, which is 16, 24, or 32 bytes, respectively. You can use a third-party application or the generateAesKey method to generate this key for you.

i don't think so you can able do it directly 
..
 
SandhyaSandhya (Salesforce Developers) 
Hi,

You can refer below link for similar discussion.

https://developer.salesforce.com/forums/?id=906F00000008yfxIAA
 
Please mark it as Solved if my reply was helpful. It will make it available for other as the proper solution.
 
Thanks and Regards
Sandhya