+ Start a Discussion
sivaextsivaext 

decrypt challenge in salesforce from external system

We have integrating salesforce with external system. External system have two factor authetication process.
Step1 : We are calling first URL to get challenge. - Working fine.
Step2 : We need to decrypt challenge in step2. We have an issues to decrypt the challenge, the error is "InValid parameter exception, private key must have 16 bytes" .

String challenge = 'NdqeqeqYQVyWaq0jYyB71Odhog==';
blob challenge1 = EncodingUtil.base64Decode(challenge);
String mkey = 'zxvfg12';// client ask to convert into 16bytes but salesforce doesn't support.
blob base64key = EncodingUtil.base64Decode(mpin);
Blob decrypted = Crypto.decryptWithManagedIV('AES128', base64key, challenge1);
system.debug('.......'+decrypted);
String decryptedString = decrypted.toString();
System.debug('......'+decryptedString);

Thanks in Advance.

Siva.
Raj VakatiRaj Vakati
Salesforce Encrypt will use 16 , 32 bits private keys. You are using "challenge" which is more than 16 


AES128 algorithms​
Blob initializationVector = Blob.valueOf('SixtenDigitlen16');
Blob key = Crypto.generateAesKey(128);
Blob cipherText = Blob.valueOf('The Data to be encrypted');
Blob encrypted = Crypto.encrypt('AES128', key, initializationVector, cipherText);
 
 
Blob decrypted = Crypto.decrypt('AES128', key, initializationVector, encrypted);
String decryptedString = decrypted.toString();
System.debug(decryptedString);


AES192 algorithms

 
Blob initializationVector = Blob.valueOf('123456789012345678901234');
Blob key = Crypto.generateAesKey(192);
Blob cipherText = Blob.valueOf('The Data to be encrypted');
Blob encrypted = Crypto.encrypt('AES192', key, initializationVector, cipherText);
 
Blob decrypted = Crypto.decrypt('AES192', key, initializationVector, encrypted);
String decryptedString = decrypted.toString();
System.debug(decryptedString);


AES256 algorithms
 
Blob initializationVector = Blob.valueOf('12345678901234567890123456789012');
Blob key = Crypto.generateAesKey(256);
Blob cipherText = Blob.valueOf('The Data to be encrypted');
Blob encrypted = Crypto.encrypt('AES256', key, initializationVector, cipherText);
 
 
Blob decrypted = Crypto.decrypt('AES256', key, initializationVector, encrypted);
String decryptedString = decrypted.toString();
System.debug(decryptedString);