您好,欢迎访问一九零五行业门户网

采用Oracle的dbms_obfuscation_toolkit的加密和解密详解

前一两天研究了一下oracle的加密算法,结合自己的实践经历和 oracle9i supplied pl/sql packages and types reference. 加密(encr
前一两天研究了一下oracle的加密算法,结合自己的实践经历和 oracle9i supplied pl/sql packages and types reference. 加密(encrypt)解密(decrypt)是采用 oracle dbms_obfuscation_toolkit package.
利用这个包,我们可以对数据进行des,triple des或者md5加密.
desgetkey   -- 产生密钥,用于des算法
   des3getkey  -- 产生密钥,用于triple des算法
   desencrypt  -- 用des算法加密数据
   desdecrypt  -- 用des算法解密数据
   des3encrypt -- 用triple des算法加密数据
   des3decrypt -- 用des算法解密数据
   md5         -- 用md5算法加密数据
triple des (3des) is a far stronger cipher than des; the resulting ciphertext (encrypted data) is much harder to break using an exhaustive search: 2**112 or 2**168 attempts instead of 2**56 attempts  这是怎么样的一个概念呢? 以现在的计算机计算能力来说吧,
uppose you build a computer capable of making 1000 attempts each second. how long would it take to exhaust 2 to the 56 (256) attempts?   it will go supernova many billions of years before you'll finish.
下面看看对字符串: password 加密的过程:
declare
input_string        varchar2(16) := 'password';
key_string          varchar2(8)  := 'oracle9i';
encrypted_string    varchar2(2048);
decrypted_string    varchar2(2048);
error_in_input_buffer_length exception;
pragma exception_init(error_in_input_buffer_length, -28232);
   input_buffer_length_err_msg varchar2(100) :=
    '*** des input buffer not a multiple of 8 bytes ***';
begin
   dbms_output.put_line('> ========= begin test =========');
   dbms_output.put_line('> input string                 : ' ||
input_string);
   --begin       dbms_obfuscation_toolkit.desencrypt(
                   input_string => input_string,
                   key_string => key_string,
                   encrypted_string => encrypted_string );
      dbms_output.put_line('> encrypted string             : ' ||
                   encrypted_string);
-- add desdecrypt as shown, change raw to key_string
      dbms_obfuscation_toolkit.desdecrypt(
                   input_string => encrypted_string,
                   key_string => key_string,
                   decrypted_string => decrypted_string);
      dbms_output.put_line('> decrypted output             : ' ||
                   decrypted_string);
      dbms_output.put_line('>  ');     
      if input_string =
                   decrypted_string then
         dbms_output.put_line('> des encryption and decryption successful');
      end if;
exception
when error_in_input_buffer_length then
      dbms_output.put_line('> ' || input_buffer_length_err_msg);
end;
运行的结果:
> ========= begin test =========
> input string                 : password
> encrypted string             : .]%.?—i
> decrypted output             : password

> des encryption and decryption successful
这里的encrypted string不同的sql/plus版本是不同的结果的,因为字符集不同,这里必段要注意:加密的字符串(input_string)必须是8的倍数哦,其实加密后的字符串也是8的倍数,如果不是的话,结果就是:
> ========= begin test =========
> input string                 : passwo1rd
> *** des input buffer not a multiple of 8 bytes ***

其它类似信息

推荐信息