Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Blob cryptoKey = Crypto.generateAesKey(128);
- System.debug('KeyBlobSize:-'+cryptoKey.size());
- System.debug('Blob:-'+EncodingUtil.base64Encode(cryptoKey));
- Blob newcryptoKey128 = Blob.valueOf('xGhMrqIixKvQ4S1bqv8CYw==');
- Blob newcryptoKey192 = Blob.valueOf('kBsCore1SUxZ8sTxSU5FCGqUGLhJ8IGq');
- Blob newcryptoKey256 = Blob.valueOf('Wc0gT/1xfFAjlRwip7l7MmEdjw7DzMXamEHLjyCOQQ0=');
- system.debug('Size1:-'+newcryptoKey128.size());
- system.debug('Size2:-'+newcryptoKey192.size());
- system.debug('Size3:-'+newcryptoKey256.size());
- Blob data = Blob.valueOf('Test data to encrypted');
- Blob encryptedData = Crypto.encryptWithManagedIV('AES256', newcryptoKey256, data);
- EXCEPTION: System.InvalidParameterValueException: Invalid private key. Must be 32 bytes.
- STACKTRACE: Class.System.Crypto.encryptWithManagedIV: line 55, column 1
- String algorithmName = 'AES256';
- Blob privateKey = Crypto.generateAesKey(256);
- Blob data = Blob.valueOf('Test data to encrypted');
- Blob encryptedData = Crypto.encryptWithManagedIV(algorithmName, privateKey, data);
- String encodedString = EncodingUtil.base64Encode(encryptedData);
- Blob decodedData=EncodingUtil.base64Decode(encodedString);
- Blob decryptedData = Crypto.decryptWithManagedIV(algorithmName, privateKey, decodedData);
Add Comment
Please, Sign In to add comment