I am trying to match PLSQL dbms_crypto with Javascript crypto-js. I want to encrypt in JS and decrypt in PLSQL, but for testing, I am encrypting in both to see if I can get the encrypted value to match.
I followed this as much as I could but I am still stuck.
dbms_crypto output mismatches with crypto-js
PLSQL
FUNCTION cl_encrypt (p_string VARCHAR2, p_key VARCHAR2)
RETURN VARCHAR2
AS
lv_whats_my_name VARCHAR2 (100) := 'cl_utilities.cl_encrypt';
v_encrypted_raw RAW (32000);
v_key RAW (320);
v_encryption_type PLS_INTEGER := DBMS_CRYPTO.encrypt_aes256 + DBMS_CRYPTO.chain_cbc + DBMS_CRYPTO.pad_pkcs5;
BEGIN
v_key := RAWTOHEX (UTL_I18N.string_to_raw (p_key, 'AL32UTF8'));
v_encrypted_raw :=
DBMS_CRYPTO.encrypt (src => UTL_I18N.string_to_raw (p_string, 'AL32UTF8'), typ => v_encryption_type, key => v_key,iv=>utl_raw.cast_to_raw(1));
RETURN UTL_RAW.cast_to_varchar2 (UTL_ENCODE.base64_encode (v_encrypted_raw));
END;
Javascript
const CryptoJS = require('crypto-js');
const key = 'some key phrase to 0129034676438'
const message = 'bob is your uncle'
var encrypted = CryptoJS.AES.encrypt(
message,
CryptoJS.enc.Base64.parse( Buffer.from(key).toString('hex')),
{ iv: CryptoJS.enc.Utf8.parse(1), mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 });
console.log("encrypted vaule :: " + encrypted );
```
Key : 'some key phrase to 0129034676438'
message: 'bob is your uncle'
iv: 1
Plsql Encrypted value
UiJjrdgefVCcY1aJNuIt+oPPAPNOtnVTsE1g3sOwxiU=
Javascript value
3UcXtyd9amnyjCYXKqi4ZrqB48ZerohDON80i1h4v2U=