Guest User

Untitled

a guest
Jan 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. Blob cryptoKey = Crypto.generateAesKey(128);
  2. System.debug('KeyBlobSize:-'+cryptoKey.size());
  3. System.debug('Blob:-'+EncodingUtil.base64Encode(cryptoKey));
  4.  
  5. Blob newcryptoKey128 = Blob.valueOf('xGhMrqIixKvQ4S1bqv8CYw==');
  6. Blob newcryptoKey192 = Blob.valueOf('kBsCore1SUxZ8sTxSU5FCGqUGLhJ8IGq');
  7. Blob newcryptoKey256 = Blob.valueOf('Wc0gT/1xfFAjlRwip7l7MmEdjw7DzMXamEHLjyCOQQ0=');
  8.  
  9. system.debug('Size1:-'+newcryptoKey128.size());
  10. system.debug('Size2:-'+newcryptoKey192.size());
  11. system.debug('Size3:-'+newcryptoKey256.size());
  12.  
  13. Blob data = Blob.valueOf('Test data to encrypted');
  14. Blob encryptedData = Crypto.encryptWithManagedIV('AES256', newcryptoKey256, data);
  15.  
  16. EXCEPTION: System.InvalidParameterValueException: Invalid private key. Must be 32 bytes.
  17. STACKTRACE: Class.System.Crypto.encryptWithManagedIV: line 55, column 1
  18.  
  19. String algorithmName = 'AES256';
  20. Blob privateKey = Crypto.generateAesKey(256);
  21. Blob data = Blob.valueOf('Test data to encrypted');
  22. Blob encryptedData = Crypto.encryptWithManagedIV(algorithmName, privateKey, data);
  23. String encodedString = EncodingUtil.base64Encode(encryptedData);
  24.  
  25. Blob decodedData=EncodingUtil.base64Decode(encodedString);
  26. Blob decryptedData = Crypto.decryptWithManagedIV(algorithmName, privateKey, decodedData);
Add Comment
Please, Sign In to add comment