Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Encryption Decryption using DBMS_CRYPTO.ENCRYPT_AES256 in oracle

PrithySep 18 2017 — edited Sep 19 2017

My input string is : CR12801

I want my decrypt string : 00FAD6ADD6224CBE91CA1E50EF39DDA2010000001537B666CDDB18DA7DC15506545A6CEDFA0459CBE0027F9D2D52DB3E1D82D4BD

Using Procedure:

DECLARE

   input_string      VARCHAR2 (2000) := 'CR12801';

  output_string     VARCHAR2 (200);

   encrypted_raw     RAW (2000);               -- stores encrypted binary text

   decrypted_raw     RAW (2000);                -- stores decrypted binarytext

  num_key_bytes     NUMBER := 256 / 8;       -- key length 256 bits (32bytes)

  key_bytes_raw     RAW (32);                 -- stores 256-bit encryption key

   encryption_type   PLS_INTEGER

      :=                                               -- total encryptiontype

        DBMS_CRYPTO.ENCRYPT_AES256

         + DBMS_CRYPTO.CHAIN_CBC

         + DBMS_CRYPTO.PAD_PKCS5;

BEGIN

   DBMS_OUTPUT.PUT_LINE ('Original string: ' || input_string);

   key_bytes_raw :=

      UTL_I18N.STRING_TO_RAW ('Metba123Metba123Metba123Metba123');

   encrypted_raw :=

      DBMS_CRYPTO.ENCRYPT (

         src   => UTL_I18N.STRING_TO_RAW (input_string, 'AL32UTF8'),

         typ   => encryption_type,

         key   => key_bytes_raw);

   -- The encrypted value "encrypted_raw" can be used here

DBMS_OUTPUT.PUT_LINE ('Encrypted string: ' || 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;

  • But using this procedure i found the decrypted value like  ' DF0635E425C654DCEDBEAC05A8A0AA46'
  • But i want the value like '00FAD6ADD6224CBE91CA1E50EF39DDA2010000001537B666CDDB18DA7DC15506545A6CEDFA0459CBE0027F9D2D52DB3E1D82D4BD '

Is there any way to find the exact value what i mentioned ?

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 17 2017
Added on Sep 18 2017
10 comments
2,615 views