Oracle 是否有任何内置的哈希函数?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11075452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does Oracle have any built-in hash function?
提问by moorara
Possible Duplicate:
Is there any hash function in PL/SQL?
可能的重复:
PL/SQL 中是否有任何哈希函数?
I have a column with NCLOB database type in Oracle 11g. I need to get a hash value for its content. How can I do this using any built-in Oracle function or inside a PL/SQL SP in Oracle?
我在 Oracle 11g 中有一个 NCLOB 数据库类型的列。我需要获取其内容的哈希值。如何使用任何内置 Oracle 函数或在 Oracle 中的 PL/SQL SP 中执行此操作?
回答by Andrew Martinez
Yes: hashing and encrypting (related but not exactly the same) are all done via the SYS package DBMS_CRYPTO.
是的:散列和加密(相关但不完全相同)都是通过 SYS 包 DBMS_CRYPTO 完成的。
Simple SHA-1 Hashing
简单的 SHA-1 哈希
l_hash := dbms_crypto.hash( l_src, dbms_crypto.HASH_SH1 );
Simple MD5 Hashing
简单的 MD5 哈希
l_hash := dbms_crypto.hash( l_src, dbms_crypto.HASH_MD5 );
Overview of dbms_crypto.hash()
dbms_crypto.hash() 概述
The hash() function is overloaded to accept the following types: RAW, BLOB, and CLOB. According to the implicity data conversionsfor raw acceptable input types are RAW, CHAR, VARCHAR2, NCHAR, NVARCHAR2, LONG, BLOB. All other data types (DATE, TIMESTAMP, etc) not covered under RAW/implicit RAW conversion, BLOB, and CLOB will have to be passed through TO_CHAR() first.
hash() 函数被重载以接受以下类型:RAW、BLOB 和 CLOB。根据原始可接受输入类型的隐式数据转换为 RAW、CHAR、VARCHAR2、NCHAR、NVARCHAR2、LONG、BLOB。RAW/隐式 RAW 转换、BLOB 和 CLOB 未涵盖的所有其他数据类型(DATE、TIMESTAMP 等)必须首先通过 TO_CHAR() 传递。
It is worth noting that dbms_crypto.hash() supports the following hashing algorithms:
值得注意的是 dbms_crypto.hash() 支持以下散列算法:
- HASH_MD4
- HASH_MD5
- HASH_SH1
- HASH_MD4
- HASH_MD5
- HASH_SH1
Passwords: Just In Case
密码:以防万一
If you are storing passwords, I suggest that you use a password storage hash (bcrypt, PBKDF2, or scrypt) instead of a cryptographic hash (md5, sha-1, etc). The difference is that password storage hashes are meant to take time to break while cryptographic hashes are meant to be done quickly. When attacking a system's password list via brute force it orders of magnitude more time intensive when attempting to break a salted value that is passed through a cryptographic algorithm. Consider that using a password hash on a single value can take ~100ms (not much for a single authentic login), but very slow for a brute force (millions/billions of attempts per password) over your entire password list.
如果您要存储密码,我建议您使用密码存储哈希(bcrypt、PBKDF2 或 scrypt)而不是加密哈希(md5、sha-1 等)。不同之处在于密码存储哈希需要时间来破解,而加密哈希需要快速完成。当通过蛮力攻击系统的密码列表时,在尝试破解通过加密算法传递的加盐值时,时间密集程度要高几个数量级。考虑到在单个值上使用密码哈希可能需要大约 100 毫秒(对于单个真实登录来说并不多),但对于整个密码列表的蛮力(每个密码数百万/数十亿次尝试)来说非常慢。
Oracle Hates Password Hashes
Oracle 讨厌密码哈希
For what its worth I am not aware of any packages from Oracle that provide password hashing support. You can however accomplish this by using 'loadjava' and putting a Java bcrypt implementation within the JVM that runs withing Oracle's RDBMS. You can then use a PL/SQL wrapperto call your Java class that implements bcrypt. If you are using a middle-tier you can use many other options available to you in that language (.NET, PHP, Perl, Ruby, Python, Java, etc) and skip trying to use 'loadjava'.
至于它的价值,我不知道来自 Oracle 的任何提供密码散列支持的软件包。但是,您可以通过使用“ loadjava”并将 Java bcrypt 实现放入与 Oracle 的 RDBMS 一起运行的 JVM 中来完成此操作。然后,您可以使用PL/SQL 包装器来调用实现 bcrypt 的 Java 类。如果您使用的是中间层,您可以使用该语言(.NET、PHP、Perl、Ruby、Python、Java 等)中可用的许多其他选项,并跳过尝试使用“loadjava”。
I meant encryption not hashes!
我的意思是加密而不是哈希!
In case the hashing you need is not covered by dbms_crypto.hash(), you might be looking for encryption via dbms_crypto.encrypt which works very similarly except that it takes in the following types:
如果 dbms_crypto.hash() 未涵盖您需要的散列,您可能会通过 dbms_crypto.encrypt 寻找加密,它的工作原理非常相似,但它采用以下类型:
- ENCRYPT_DES
- ENCRYPT_3DES_2KEY
- ENCRYPT_3DES
- ENCRYPT_AES
- ENCRYPT_PBE_MD5DES
- ENCRYPT_AES128
- ENCRYPT_AES192
- ENCRYPT_AES256
- ENCRYPT_DES
- ENCRYPT_3DES_2KEY
- ENCRYPT_3DES
- ENCRYPT_AES
- ENCRYPT_PBE_MD5DES
- ENCRYPT_AES128
- ENCRYPT_AES192
- ENCRYPT_AES256
Here is the full 11gR2 documentation on DBMS_CRYPTO. All other versions are available via tahiti.oracle.com. Just click on your version and then search for 'dbms_crypto'.
这是关于 DBMS_CRYPTO的完整11gR2 文档。所有其他版本均可通过tahiti.oracle.com 获得。只需单击您的版本,然后搜索“dbms_crypto”。