Oracle是否有内置的散列函数? [英] Does Oracle have any built-in hash function?

查看:149
本文介绍了Oracle是否有内置的散列函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:


我在Oracle 11g中有一个包含NCLOB数据库类型的列。我需要为其内容获取哈希值。我如何使用任何内置的Oracle函数或在Oracle中的PL / SQL SP中执行此操作?

是:hashing和加密(相关但不完全相同)都是通过SYS包DBMS_CRYPTO完成的。

简单SHA-1散列

  l_hash:= dbms_crypto.hash(l_src,dbms_crypto.HASH_SH1); 

简单MD5哈希

  l_hash:= dbms_crypto.hash(l_src,dbms_crypto.HASH_MD5); 

dbms_crypto.hash()的概述



hash()函数被重载以接受以下类型:RAW,BLOB和CLOB。根据原始可接受的隐含数据转换输入类型是RAW,CHAR,VARCHAR2,NCHAR,NVARCHAR2,LONG,BLOB。所有未包含在RAW /隐式RAW转换,BLOB和CLOB中的其他数据类型(DATE,TIMESTAMP等)都必须首先通过TO_CHAR()传递。

值得注意的是,dbms_crypto.hash()支持以下散列算法:
$ b


  • HASH_MD4

  • HASH_MD5

  • HASH_SH1



密码:如果你正在存储密码,我建议你使用密码存储哈希(bcrypt,PBKDF2或scrypt)而不是密码哈希(md5,sha-1等) 。不同之处在于,密码存储哈希意味着需要一段时间才能破解,而密码哈希要尽快完成。当试图破解通过加密算法传递的盐值时,通过强制攻击系统的密码列表时,它会花费更多的时间。考虑在单个值上使用密码散列可能需要大约100毫秒(对于单个可信登录而言,并不多),但对于整个密码列表中的暴力破解(每个密码尝试数百万次/十亿次)非常缓慢。

Oracle Hates密码哈希值

来自Oracle的任何提供密码散列支持的软件包。但是,您可以使用 loadjava 来完成此操作'并在运行Oracle RDBMS的JVM中放入Java bcrypt实现。然后,您可以使用 PL / SQL包装器调用实现bcrypt的Java类。如果您使用的是中间层,您可以使用该语言提供的许多其他选项(.NET,PHP,Perl,Ruby,Python,Java等),并跳过尝试使用'loadjava'。



我的意思是加密不是哈希值!

如果您需要的散列未被dbms_crypto覆盖。 hash(),你可能正在通过dbms_crypto.encrypt寻找加密,它的工作原理非常相似,除了它需要以下类型:


  • ENCRYPT_DES
  • ENCRYPT_3DES_2KEY

  • ENCRYPT_3DES

  • ENCRYPT_AES

  • ENCRYPT_PBE_MD5DES
  • li>
  • ENCRYPT_AES128

  • ENCRYPT_AES192

  • ENCRYPT_AES256

    以下是完整的 11gR2文档在DBMS_CRYPTO上。所有其他版本均可通过 tahiti.oracle.com 获取。只需点击您的版本,然后搜索'dbms_crypto'。


    Possible Duplicate:
    Is there any hash function in 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?

    解决方案

    Yes: hashing and encrypting (related but not exactly the same) are all done via the SYS package DBMS_CRYPTO.

    Simple SHA-1 Hashing

    l_hash := dbms_crypto.hash( l_src, dbms_crypto.HASH_SH1 );
    

    Simple MD5 Hashing

    l_hash := dbms_crypto.hash( l_src, dbms_crypto.HASH_MD5 );
    

    Overview of dbms_crypto.hash()

    The hash() function is overloaded to accept the following types: RAW, BLOB, and CLOB. According to the implicity data conversions for 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.

    It is worth noting that dbms_crypto.hash() supports the following hashing algorithms:

    • 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.

    Oracle Hates Password Hashes

    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 wrapper to 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'.

    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:

    • 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'.

    这篇关于Oracle是否有内置的散列函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆