如何取BLOB类型的MD5加密值
答案:2 悬赏:40 手机版
解决时间 2021-12-21 11:23
- 提问者网友:那叫心脏的地方装的都是你
- 2021-12-20 10:51
如何取BLOB类型的MD5加密值
最佳答案
- 五星知识达人网友:低音帝王
- 2021-12-20 10:56
from ragini.deshpande
Here is the my_encryption package code ...........
CREATE OR REPLACe PACKAGE BODY my_encryption IS
ps_encryption_key RAW(32);
INTERNAL_BAD_KEY exception;
PRAGMA EXCEPTION_INIT(INTERNAL_BAD_KEY, -28231);
INTERNAL_BAD_DATA exception;
PRAGMA EXCEPTION_INIT(INTERNAL_BAD_DATA, -28232);
FUNCTION get_case_encryption_key(pi_cas_id IN ELS_CASES.ID%TYPE) RETURN RAW IS
key RAW(16);
CURSOR c_case_key(b_cas_id ELS_CASES.ID%TYPE) IS
SELECT encryption_key
FROM els_cases
WHERe id = b_cas_id;
BEGIN
OPEN c_case_key(pi_cas_id);
FETCH c_case_key INTO key;
CLOSE c_case_key;
RETURN key;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE NO_CASE;
END;
PROCEDURE set_master_key(pi_key IN RAW) IS
BEGIN
IF LENGTHB(pi_key) != 32 THEN
RAISE BAD_KEY;
END IF;
ps_encryption_key := pi_key;
END;
FUNCTION set_master_key(pi_key IN RAW) RETURN VARCHAR2 IS
BEGIN
set_master_key(pi_key);
RETURN 'Y';
END;
PROCEDURE set_case_key(pi_master_key IN RAW,
pi_cas_id IN ELS_CASES.ID%TYPE) IS
BEGIN
ps_encryption_key := pi_master_key;
ps_encryption_key := decrypt(pi_data=>get_case_encryption_key(pi_cas_id));
END;
FUNCTION set_case_key(pi_master_key IN RAW,
pi_cas_id IN ELS_CASES.ID%TYPE) RETURN VARCHAR2 IS
BEGIN
set_case_key(pi_master_key,pi_cas_id);
RETURN 'Y';
END;
FUNCTION encrypt(pi_data IN RAW) RETURN RAW IS
BEGIN
RETURN dbms_obfuscation_toolkit.DES3Encrypt(input => pi_data,
key => ps_encryption_key);
EXCEPTION
WHEN INTERNAL_BAD_DATA THEN
RAISE BAD_DATA;
WHEN INTERNAL_BAD_KEY THEN
RAISE BAD_KEY;
END;
FUNCTION encrypt(pi_blob IN BLOB) RETURN BLOB IS
result blob;
blob_length PLS_INTEGER := dbms_lob.getlength(pi_blob);
max_chunk_length PLS_INTEGER := 2000;
chunk_length PLS_INTEGER;
pointer PLS_INTEGER := 1;
chunk RAW(2000);
pad RAW(1) := utl_raw.substr(utl_raw.cast_to_raw('0'),1,1);
BEGIN
dbms_lob.createtemporary(result, TRUE, dbms_lob.call);
WHILE (pointer <= blob_length) LOOP
chunk_length := LEAST(max_chunk_length,blob_length-pointer+1);
chunk := dbms_lob.substr(pi_blob,chunk_length,pointer);
WHILE mod(chunk_length,8) !=0 LOOP
chunk := utl_raw.concat(chunk,pad);
chunk_length := chunk_length+1;
END LOOP;
dbms_lob.writeappend(result,
chunk_length,
encrypt(pi_data => chunk)
);
pointer := pointer + chunk_length;
END LOOP;
RETURN result;
END;
FUNCTION decrypt(pi_data IN RAW) RETURN RAW IS
BEGIN
RETURN dbms_obfuscation_toolkit.DES3Decrypt(input => pi_data,
key => ps_encryption_key);
EXCEPTION
WHEN INTERNAL_BAD_DATA THEN
RAISE BAD_DATA;
WHEN INTERNAL_BAD_KEY THEN
RAISE BAD_KEY;
END;
FUNCTION decrypt(pi_blob IN BLOB,
pi_size IN PLS_INTEGER) RETURN BLOB IS
result BLOB;
blob_length PLS_INTEGER := dbms_lob.getlength(pi_blob);
max_chunk_length PLS_INTEGER := 2000;
chunk_length PLS_INTEGER;
pointer PLS_INTEGER := 1;
BEGIN
dbms_lob.createtemporary(result, TRUE, dbms_lob.call);
WHILE (pointer <= blob_length) LOOP
chunk_length := LEAST(max_chunk_length,blob_length-pointer+1);
dbms_lob.writeappend(result,
chunk_length,
decrypt(pi_data => dbms_lob.substr(pi_blob,
chunk_length,
pointer
)
)
);
pointer := pointer + chunk_length;
END LOOP;
dbms_lob.trim(result,pi_size);
RETURN result;
END;
PROCEDURE CLEAR IS
BEGIN
ps_encryption_key:=null;
END;
END;
/
and here is the PL/sql I run before running the sql stmt
DECLARE
mkey LONG RAW;
BEGIN
mkey := UTL_RAW.CAST_TO_RAW ('&&key');
my_encryption.set_master_key(mkey);
my_encryption.set_case_key(mkey,&&case_id);
END;
mkey is a 16 digit key .
and the encrypted_contents I'm trying to decrypt is a BLOB.
select my_encryption.decrypt(encrypted_contents,file_size),mime_type
from my_drafts where id = &&draft_id;
I hope this makes sense .
Ragini
Here is the my_encryption package code ...........
CREATE OR REPLACe PACKAGE BODY my_encryption IS
ps_encryption_key RAW(32);
INTERNAL_BAD_KEY exception;
PRAGMA EXCEPTION_INIT(INTERNAL_BAD_KEY, -28231);
INTERNAL_BAD_DATA exception;
PRAGMA EXCEPTION_INIT(INTERNAL_BAD_DATA, -28232);
FUNCTION get_case_encryption_key(pi_cas_id IN ELS_CASES.ID%TYPE) RETURN RAW IS
key RAW(16);
CURSOR c_case_key(b_cas_id ELS_CASES.ID%TYPE) IS
SELECT encryption_key
FROM els_cases
WHERe id = b_cas_id;
BEGIN
OPEN c_case_key(pi_cas_id);
FETCH c_case_key INTO key;
CLOSE c_case_key;
RETURN key;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE NO_CASE;
END;
PROCEDURE set_master_key(pi_key IN RAW) IS
BEGIN
IF LENGTHB(pi_key) != 32 THEN
RAISE BAD_KEY;
END IF;
ps_encryption_key := pi_key;
END;
FUNCTION set_master_key(pi_key IN RAW) RETURN VARCHAR2 IS
BEGIN
set_master_key(pi_key);
RETURN 'Y';
END;
PROCEDURE set_case_key(pi_master_key IN RAW,
pi_cas_id IN ELS_CASES.ID%TYPE) IS
BEGIN
ps_encryption_key := pi_master_key;
ps_encryption_key := decrypt(pi_data=>get_case_encryption_key(pi_cas_id));
END;
FUNCTION set_case_key(pi_master_key IN RAW,
pi_cas_id IN ELS_CASES.ID%TYPE) RETURN VARCHAR2 IS
BEGIN
set_case_key(pi_master_key,pi_cas_id);
RETURN 'Y';
END;
FUNCTION encrypt(pi_data IN RAW) RETURN RAW IS
BEGIN
RETURN dbms_obfuscation_toolkit.DES3Encrypt(input => pi_data,
key => ps_encryption_key);
EXCEPTION
WHEN INTERNAL_BAD_DATA THEN
RAISE BAD_DATA;
WHEN INTERNAL_BAD_KEY THEN
RAISE BAD_KEY;
END;
FUNCTION encrypt(pi_blob IN BLOB) RETURN BLOB IS
result blob;
blob_length PLS_INTEGER := dbms_lob.getlength(pi_blob);
max_chunk_length PLS_INTEGER := 2000;
chunk_length PLS_INTEGER;
pointer PLS_INTEGER := 1;
chunk RAW(2000);
pad RAW(1) := utl_raw.substr(utl_raw.cast_to_raw('0'),1,1);
BEGIN
dbms_lob.createtemporary(result, TRUE, dbms_lob.call);
WHILE (pointer <= blob_length) LOOP
chunk_length := LEAST(max_chunk_length,blob_length-pointer+1);
chunk := dbms_lob.substr(pi_blob,chunk_length,pointer);
WHILE mod(chunk_length,8) !=0 LOOP
chunk := utl_raw.concat(chunk,pad);
chunk_length := chunk_length+1;
END LOOP;
dbms_lob.writeappend(result,
chunk_length,
encrypt(pi_data => chunk)
);
pointer := pointer + chunk_length;
END LOOP;
RETURN result;
END;
FUNCTION decrypt(pi_data IN RAW) RETURN RAW IS
BEGIN
RETURN dbms_obfuscation_toolkit.DES3Decrypt(input => pi_data,
key => ps_encryption_key);
EXCEPTION
WHEN INTERNAL_BAD_DATA THEN
RAISE BAD_DATA;
WHEN INTERNAL_BAD_KEY THEN
RAISE BAD_KEY;
END;
FUNCTION decrypt(pi_blob IN BLOB,
pi_size IN PLS_INTEGER) RETURN BLOB IS
result BLOB;
blob_length PLS_INTEGER := dbms_lob.getlength(pi_blob);
max_chunk_length PLS_INTEGER := 2000;
chunk_length PLS_INTEGER;
pointer PLS_INTEGER := 1;
BEGIN
dbms_lob.createtemporary(result, TRUE, dbms_lob.call);
WHILE (pointer <= blob_length) LOOP
chunk_length := LEAST(max_chunk_length,blob_length-pointer+1);
dbms_lob.writeappend(result,
chunk_length,
decrypt(pi_data => dbms_lob.substr(pi_blob,
chunk_length,
pointer
)
)
);
pointer := pointer + chunk_length;
END LOOP;
dbms_lob.trim(result,pi_size);
RETURN result;
END;
PROCEDURE CLEAR IS
BEGIN
ps_encryption_key:=null;
END;
END;
/
and here is the PL/sql I run before running the sql stmt
DECLARE
mkey LONG RAW;
BEGIN
mkey := UTL_RAW.CAST_TO_RAW ('&&key');
my_encryption.set_master_key(mkey);
my_encryption.set_case_key(mkey,&&case_id);
END;
mkey is a 16 digit key .
and the encrypted_contents I'm trying to decrypt is a BLOB.
select my_encryption.decrypt(encrypted_contents,file_size),mime_type
from my_drafts where id = &&draft_id;
I hope this makes sense .
Ragini
全部回答
- 1楼网友:几近狂妄
- 2021-12-20 11:14
当您将此哈希算法应用到任意数量的数据例如,一个二进制文件,结果是一个散列或消息摘要。此哈希具有固定的大小。md5 是创建一个 128 位的哈希值的哈希算法。sha-1 是创建一个 160 位的哈希值的哈希算法。
文件校验和完整性验证程序 (fciv) 实用程序可用于计算一个文件的 md5 或 sha-1 加密哈希值。有关文件校验和完整性验证程序 (fciv) 实用程序的其他信息,请单击下面的文章编号,以查看 microsoft 知识库中相应的文章:
841290可用性和文件校验和完整性验证程序实用程序的说明
计算的 md5 和 sha-1 哈希值的文件,请在命令行键入以下命令:
fciv-md5-sha1 path\filename.ext
例如,若要计算在%systemroot%文件夹中 \system32 shdocvw.dll 文件的 md5 和 sha-1 哈希值,请键入下面的命令:
fciv-md5-sha1 c:\windows\system32\shdocvw.dll
这篇文章中的信息适用于:
customer service and support information
关键字:
kbmt kmcustomerservice kbhowto kb889768 kbmtzh
机器翻译
注意:这篇文章是由无人工介入的微软自动的机器翻译软件翻译完成。微软很高兴能同时提供给您由人工翻译的和由机器翻译的文章, 以使您能使用您的语言访问所有的知识库文章。然而由机器翻译的文章并不总是完美的。它可能存在词汇,语法或文法的问题,就像是一个外国人在说中文时总是可能犯这样的错误。虽然我们经常升级机器翻译软件以提高翻译质量,但是我们不保证机器翻译的正确度,也不对由于内容的误译或者客户对它的错误使用所引起的任何直接的, 或间接的可能的问题负责。
点击这里察看该文章的英文版: 889768
microsoft和/或其各供应商对于为任何目的而在本服务器上发布的文件及有关图形所含信息的适用性,不作任何声明。 所有该等文件及有关图形均"依样"提供,而不带任何性质的保证。microsoft和/或其各供应商特此声明,对所有与该等信息有关的保证和条件不负任何责任,该等保证和条件包括关于适销性、符合特定用途、所有权和非侵权的所有默示保证和条件。在任何情况下,在由于使用或运行本服务器上的信息所引起的或与该等使用或运行有关的诉讼中,microsoft和/或其各供应商就因丧失使用、数据或利润所导致的任何特别的、间接的、衍生性的损害或任何因使用而丧失所导致的之损害、数据或利润不负任何责任
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯