Re: encrypt Chinese or Japanese

From: DA Morgan <damorgan_at_psoug.org>
Date: Thu, 28 Dec 2006 09:25:24 -0800
Message-ID: <1167326718.797665_at_bubbleator.drizzle.com>


yongjia wrote:
> hi all:
>
> I use dbms_obfuscation_toolkit.desencrypt to encrypt Chinese or Japanese
> vbstring
> but when I decrypt it ,I can not get the right string
>
> who can tell me how to resolve it?
>
>
> ----------------------------------------
> create or replace function get_encrypted_string(orgstr varchar2)
> return varchar2 as
> keystr varchar2(8) := 'angoukey';
> encstr varchar2(40);
> v_text varchar2(40);
> begin
> v_text := rpad( orgstr, (trunc(length(orgstr)/8)+1)*8, chr(0));
>
> if orgstr is null then
> return null;
> end if;
>
> dbms_obfuscation_toolkit.desencrypt(
> input_string => v_text,
> key_string => keystr,
> encrypted_string => encstr
> );
>
> return encstr;
> end;
>
>
>
> create or replace function get_decrypted_string(encstr varchar2)
> return varchar2 as
> keystr varchar2(8) := 'angoukey';
> orgstr varchar2(40);
>
> begin
> if encstr is null then
> return null;
> end if;
>
> dbms_obfuscation_toolkit.desdecrypt(
> input_string => encstr,
> key_string => keystr,
> decrypted_string => orgstr
> );
>
> return rtrim(orgstr,chr(0));
> end;

Assuming since you work with multibyte languages you have resolved any character set issues:

This is just a guess as I've never worked with the Obfuscation Toolkit and a multibyte language. But you are declaring your variables using BYTE not CHARACTER and assuming that v_text varchar2(40) should be the same size as encstr varchar2(40) strikes me as potentially worth exploring.

Try declaring your input variable as VARCHAR2(40 CHAR) and your output as VARCHAR2(1000 CHAR) and see what happens.

-- 
Daniel A. Morgan
University of Washington
damorgan_at_x.washington.edu
(replace x with u to respond)
Puget Sound Oracle Users Group
www.psoug.org
Received on Thu Dec 28 2006 - 18:25:24 CET

Original text of this message