Oracle PL/SQL function DBMS_CRYPTO.PKENCRYPT is throwing error when I try to encrypt using RSA public key

217 Views Asked by At

I'm trying to create a procedure that can encrypt input text using RSA public key provided by client, using the DBMS_CRYPTO.PKENCRYPT function.

Here is the sample:

DECLARE
  ip_str     VARCHAR (200) := 'Secret Message';
  pubkey     VARCHAR (2000) := 'samplekey';
  enc_raw    RAW (2000);
  kType      PLS_INTEGER := DBMS_CRYPTO.KEY_TYPE_RSA;
  eType      PLS_INTEGER := DBMS_CRYPTO.PKENCRYPT_RSA_PKCS1_OAEP;

BEGIN

  enc_raw := DBMS_CRYPTO.PKENCRYPT
  (
    src        => UTL_I18N.STRING_TO_RAW(ip_str,'AL32UTF8'),
    pub_key    => UTL_I18N.STRING_TO_RAW(pubkey, 'AL32UTF8'),
    pubkey_alg => kType,
    enc_alg    => eType
  );

  dbms_output.put_line('Encrypted : ' || utl_raw.cast_to_varchar2(enc_raw ));
end;
/
But this is throwing me this error:
    ORA-28817: PL/SQL function returned an error.
    ORA-06512: at "SYS.DBMS_CRYPTO_FFI", line 258
    ORA-06512: at "SYS.DBMS_CRYPTO", line 143
    ORA-06512: at line 10
    28817. 00000 -  "PL/SQL function returned an error."
    *Cause:    A PL/SQL function returned an error unexpectedly.
    *Action:   This is an internal error. Enable tracing to find more
               information. Contact Oracle customer support if needed.
    *Document: NO

What am I doing wrong here?

0

There are 0 best solutions below