You are on page 1of 4

Skip to content

Accessibility Preferences
PowerView is On Support Identifier: 20970141 (Tong Cong ty...
Thanh (Available) (0) Contact Us Help

Dashboard
Knowledge
Service Requests
Patches & Updates
Community
Certifications
Systems
Collector

Global Search

Give Feedback...

Copyright (c) 2018, Oracle. All rights reserved. Oracle Confidential.

DBMS_CRYPTO.DECRYPT - ORA-28817 ORA-06512 at To


DBMS_CRYPTO_FFI (Doc ID 956603.1) Bottom

In this Document Was this document helpful?

Symptoms
Yes
Cause
No
Solution

This document is being delivered to you via


Oracle Support's Rapid Visibility (RaV) process Document Details

and therefore has not been subject to an


independent technical review.
Type: PROBLEM
Status: MODERATED
APPLIES TO:
Last Major Update: 18-Mar-2013
Last Update: 17-Apr-2018
Oracle Database - Enterprise Edition - Version
10.2.0.1 to 11.2.0.0 [Release 10.2 to 11.2]
Information in this document applies to any
platform. Related Products
Checked for relevance on 18-MAR-2013 Oracle Database -
Enterprise Edition

SYMPTOMS Information Centers

When you use DBMS_CRYPTO for encryption and


decryption, you get the below error:
Document References

SQL> create or replace function encrypt(v_stri


ng in varchar2) return varchar2 is
2 encrypted_raw RAW (2000);
3 encryption_type PLS_INTEGER := SYS.DB Recently Viewed
MS_CRYPTO.ENCRYPT_DES + SYS.DBMS_CRYPTO.CHAIN_
CBC + SYS.DBMS_CRYPTO.PAD_PKCS5; QP: Bulk Import of Price List - Current Issues For
4 v_key raw(128) := utl_i18n.string_to_raw( Oracle Applications R12.1 [1182973.1]
'artos0011', 'AL32UTF8' );
5 begin Report Manager: Step by Step Setup Guide For
6 encrypted_raw := DBMS_CRYPTO.ENCRYPT Publishing FSGs [734015.1]

7 (
Unable to Post Receipts. The Subledger Journal
8 src => UTL_I18N.STRING_TO_RAW (v
Entry Does Not Balance in the Entered Currency.
_string,'AL32UTF8'),
9 typ => encryption_type, [2102791.1]
10 key => v_key
11 ); Unable to post receipts. The Subledger Journal
12 return UTL_I18N.raw_to_char(encryp Entry Does Not Balance In The Entered Currency
ted_raw,'AL32UTF8'); [1476919.1]
13 end encrypt;
14 / Issues When Running An FSG Report - Using
Report Manager. When Publishing an FSG Report
Function created. In Excel The Excel Is Blank Or No Data Is Present
in The Excel Output [1342240.1]

SQL> create or replace function decrypt(v_str


in varchar2) return varchar2 is Show More
2 decrypted_raw raw(2000);
3 encryption_type PLS_INTEGER := SYS.DBM
S_CRYPTO.ENCRYPT_DES + SYS.DBMS_CRYPTO.CHAIN_C
BC + SYS.DBMS_CRYPTO.PAD_PKCS5;
4 v_key raw(128) := utl_i18n.string_to_raw(
'artos001', 'AL32UTF8' );
5 begin
6 decrypted_raw := DBMS_CRYPTO.Decrypt

7 (
8 src => UTL_I18N.string_to_raw(v_
str),
9 typ => encryption_type,
10 key => v_key
11 );
12 return UTL_I18N.RAW_TO_CHAR (decrypted
_raw, 'AL32UTF8');
13 end decrypt;
14 /
Function created.

SQL> select decrypt(encrypt('67634572')) from


dual;
select decrypt(encrypt('67634572')) from dual
*
ERROR at line 1:
ORA-28817: PL/SQL function returned an error.
ORA-06512: at "SYS.DBMS_CRYPTO_FFI", line 67
ORA-06512: at "SYS.DBMS_CRYPTO", line 41
ORA-06512: at "MOHAN.DECRYPT", line 6

CAUSE

Incorrect use of UTL_I18N can corrupt the


encrypted byte sequence and this error will be
raised while trying to decrypt it.

SOLUTION

When you are passing the encrypted value to the


decrypt function or for storage within database, do
not use UTL_I18N.RAW_TO_CHAR instead use
RAWTOHEX or
UTL_ENCODE.BASE64_ENCODE. Similarly for
converting back to raw do not use
UTL_I18N.STRING_TO_RAW instead use
HEXTORAW or
UTL_ENCODE.BASE64_DECODE.

Example:-

SQL> create or replace function encrypt(v_stri


ng in varchar2) return varchar2 is
2 encrypted_raw RAW (2000);
3 encryption_type PLS_INTEGER := SYS.DB
MS_CRYPTO.ENCRYPT_DES + SYS.DBMS_CRYPTO.CHAIN_
CBC + SYS.DBMS_CRYPTO.PAD_PKCS5;
4 v_key raw(128) := utl_i18n.string_to_raw(
'artos0011', 'AL32UTF8' );
5 begin
6 encrypted_raw := DBMS_CRYPTO.ENCRYPT

7 (
8 src => UTL_I18N.STRING_TO_RAW (v
_string,'AL32UTF8'),
9 typ => encryption_type,
10 key => v_key
11 );
12 return RAWTOHEX(encrypted_raw);
13 end encrypt;
14 /
Function created.

SQL> create or replace function decrypt(v_str


in varchar2) return varchar2 is
2 decrypted_raw raw(2000);
3 encryption_type PLS_INTEGER := SYS.DBM
S_CRYPTO.ENCRYPT_DES + SYS.DBMS_CRYPTO.CHAIN_C
BC + SYS.DBMS_CRYPTO.PAD_PKCS5;
4 v_key raw(128) := utl_i18n.string_to_raw(
'artos001', 'AL32UTF8' );
5 begin
6 decrypted_raw := DBMS_CRYPTO.Decrypt

7 (
8 src => HEXTORAW(v_str),
9 typ => encryption_type,
10 key => v_key
11 );
12 return UTL_I18N.RAW_TO_CHAR (decrypted
_raw, 'AL32UTF8');
13 end decrypt;
14 /

Function created.

SQL> select decrypt(encrypt('67634572')) from


dual;

DECRYPT(ENCRYPT('67634572'))
----------------------------------------------
-------
67634572

Didn't find what you are looking for? Ask in Community...

Related
Products

 Oracle Database Products > Oracle Database Suite > Oracle Database > Oracle Database - Enterprise
Edition > RDBMS

Keywords
DBMS_CRYPTO; DBMS_CRYPTO.DECRYPT; DBMS_CRYPTO.ENCRYPT; DBMS_CRYPTO_FFI

Errors
ORA-28817; ORA-6512

Back to Top

Copyright (c) 2018, Oracle. All rights reserved. Legal Notices and Terms of Use Privacy Statement

You might also like