grant execute on dbms_crypto to system; declare input_string VARCHAR2 (200) := 'Secret Message'; output_string VARCHAR2(2000); encrypted_raw RAW(2000); decrypted_raw RAW(2000); num_key_bytes NUMBER := 256/8; key_bytes_raw RAW(32); encryption_type PLS_INTEGER := DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5; begin DBMS_OUTPUT.PUT_LINE(input_string); key_bytes_raw := DBMS_CRYPTO.RANDOMBYTES(num_key_bytes); encrypted_raw := DBMS_CRYPTO.ENCRYPT ( src => UTL_I18N.STRING_TO_RAW(input_string, 'AL32UTF8'), typ => encryption_type, key => key_bytes_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(output_string); end; declare l_src_data varchar2(20); l_type pls_integer :=DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5; l_key varchar2(20) :='0123456789123456'; l_encval raw(2000); CURSOR secret_cursor IS select phonenumber from customer; begin OPEN secret_cursor; LOOP FETCH secret_cursor INTO l_src_data; l_encval :=dbms_crypto.encrypt( src=>utl_i18n.string_to_raw(l_src_data,'AL32UTF8'), typ=>l_type, key=>utl_i18n.string_to_raw(l_key,'AL32UTF8')); DBMS_OUTPUT.PUT_LINE (l_encval); EXIT WHEN secret_cursor%NOTFOUND; END LOOP; CLOSE secret_cursor; end; declare ;_src_data row(100) :=hextoraw("190248129038903853275ijdkvjkad'); l_type pls_integer :=dbms_crypto.encrypt_aes128+ + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5; l_key varchar2(20) :='0123456789123456'; l_decval raw(200); begin l_decval :=dbms_crypto.decrypt( src=>l_src_data, typ=>l_type, key=>utl_i18n.string_to_raw(l_key,'AL32UTF8')); end; SELECT Price FROM PRODUCT WHERE ProductID = 5;修正这一段代码
时间: 2024-01-30 22:03:41 浏览: 99
DBMS_c.rar_C语言实现DBMS_DBMS_c_c语言DBMS_dbms
5星 · 资源好评率100%
以下是修正后的代码:
```
grant execute on dbms_crypto to system;
-- 第一个代码块
declare
input_string VARCHAR2 (200) := 'Secret Message';
output_string VARCHAR2(2000);
encrypted_raw RAW(2000);
decrypted_raw RAW(2000);
num_key_bytes NUMBER := 256/8;
key_bytes_raw RAW(32);
encryption_type PLS_INTEGER := DBMS_CRYPTO.ENCRYPT_AES256 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
begin
DBMS_OUTPUT.PUT_LINE(input_string);
key_bytes_raw := DBMS_CRYPTO.RANDOMBYTES(num_key_bytes);
encrypted_raw := DBMS_CRYPTO.ENCRYPT(src => UTL_I18N.STRING_TO_RAW(input_string, 'AL32UTF8'), typ => encryption_type, key => key_bytes_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(output_string);
end;
-- 第二个代码块
declare
l_src_data varchar2(20);
l_type pls_integer := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
l_key varchar2(20) := '0123456789123456';
l_encval raw(2000);
cursor secret_cursor is select phonenumber from customer;
begin
open secret_cursor;
loop
fetch secret_cursor into l_src_data;
exit when secret_cursor%notfound;
l_encval := dbms_crypto.encrypt(src => utl_i18n.string_to_raw(l_src_data,'AL32UTF8'), typ => l_type, key => utl_i18n.string_to_raw(l_key,'AL32UTF8'));
dbms_output.put_line(l_encval);
end loop;
close secret_cursor;
end;
-- 第三个代码块
declare
l_src_data raw(100) := hextoraw('190248129038903853275ijdkvjkad');
l_type pls_integer := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
l_key varchar2(20) := '0123456789123456';
l_decval raw(200);
begin
l_decval := dbms_crypto.decrypt(src => l_src_data, typ => l_type, key => utl_i18n.string_to_raw(l_key,'AL32UTF8'));
end;
-- SQL 查询语句
SELECT Price FROM PRODUCT WHERE ProductID = 5;
```
注意:第三个代码块中的 `l_src_data` 变量的赋值语句中,修正了单引号和双引号的不匹配问题。
阅读全文