Hi,
I am posting this question again in a different way. I need to do encryption in AES256 + CBC + PKCS7. I have been provided with 64 character long key that I need to use.
Below is the modified code
declare
input_string VARCHAR2 (200) := 'testing1234567890|20120214-12:00:00:001';
output_string VARCHAR2 (200);
encrypted_raw RAW (2000); -- stores encrypted binary text
decrypted_raw RAW (2000); -- stores decrypted binary text
key_bytes_raw RAW (32); -- stores 256-bit encryption key
encryption_type PLS_INTEGER; -- total encryption type
begin
DBMS_OUTPUT.PUT_LINE ('Original string: ' || input_string);
encryption_type := DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
key_bytes_raw := HEXTORAW('bc82bb2613bdf3ac4d093ea4fec8cf76f49af2175f397f0466a363948eeaf6fd');
encrypted_raw := DBMS_CRYPTO.ENCRYPT
(
src => UTL_I18N.STRING_TO_RAW (input_string, 'AL32UTF8'),
typ => encryption_type,
key => key_bytes_raw
);
-- The encrypted value in the encrypted_raw variable can be used here
DBMS_OUTPUT.PUT_LINE(UTL_ENCODE.base64_encode(encrypted_raw));
decrypted_raw := DBMS_CRYPTO.DECRYPT
(
src => encrypted_raw,
typ => encryption_type,
key => key_bytes_raw
);
output_string := UTL_I18N.RAW_TO_CHAR (decrypted_raw, 'AL32UTF8');
DBMS_OUTPUT.PUT_LINE ('Decrypted string: ' || output_string);
end;
The output I am getting is
Original string: testing1234567890|20120214-12:00:00:001
7344792F32454B4953486A336E505365734B586E486A2B45694E53426E4C3632743751333353774C34776E7A6C4176486C52694C6F2F4769384C7245545167460D0A
Decrypted string: testing1234567890|20120214-12:00:00:001
I confirmed with my client, they are saying I should get below encrypted string
uYRSmXvp3TWPCyKIN+xa6QapeurC0npWQrlAlHrCcZPRDrM89NQpKdKOTPOXLX2h
As in the code it is PKCS5, not PKCS7. Please help me in achieving the above encrypted string in PL/SQL.
Thanks
-Smith