简体   繁体   English

Python是否可以识别Java中使用BCrypt的哈希密码?

[英]Can a hashed password using BCrypt in Java be recognised by Python?

I'm planning to hash user passwords using bcrypt , and to store these hashed passwords in a database. 我打算使用bcrypt哈希用户密码,并将这些哈希密码存储在数据库中。

The server that handles user account creation, and inserts the hashed password to the database is written in Java. 处理用户帐户创建并将哈希密码插入数据库的服务器是用Java编写的。

Another server that needs to access user information (including the hashed passwords) is written in Python. 需要访问用户信息(包括哈希密码)的另一台服务器是用Python编写的。

I was planning to use jBCrypt for the Java side, but before I do that I want to make sure that I'll by able to recognise/use these hashed passwords from the Python side. 我打算将jBCrypt用于Java端,但是在此之前,我想确保能够从Python端识别/使用这些哈希密码。

How I understand things, this should be no problem as long as the Python BCrypt implementation is the same as the Java implementation. 以我的理解,只要Python BCrypt实现与Java实现相同,这应该没问题。

So, can I use the passwords hashed using jBCrypt from Python? 因此,我可以使用通过Python的jBCrypt散列的密码吗? How? 怎么样?

Thanks in advance! 提前致谢!

The best way to know is to actually try it. 最好的知道方法是实际尝试。 Assuming both implementations are correct, they should be compatible, as long as you take care to re-encode data as necessary. 假设两种实现都是正确的,则它们应该兼容,只要您注意根据需要重新编码数据即可。

Typically, a hash is stored in memory either as a byte array of the raw hash, or as a ASCII hexadecimal representation. 通常,哈希以原始哈希的字节数组或ASCII十六进制表示形式存储在内存中。 The best way to know what encoding it's using is actually printing it to the console: if it looks like garbage, it'll be a raw byte array; 知道它正在使用哪种编码的最好方法是将其实际打印到控制台:如果看起来像垃圾,它将是一个原始字节数组; if it prints a hexadecimal string (0-9 and af), it's ascii encoded hexadecimal. 如果输出十六进制字符串(0-9和af),则为ASCII编码的十六进制。

Salt will probably be stored like the hash. 盐可能会像哈希一样存储。 The number of rounds is a integer. 轮数是整数。 It's up to you to store all this data in a common format. 由您决定是否以通用格式存储所有这些数据。 If you need to convert a ascii hex string to a byte array (actually, a string) in python, you can use string.encode: 如果需要在Python中将ascii十六进制字符串转换为字节数组(实际上是字符串),则可以使用string.encode:

>>> 'hello world'.encode('hex')
'68656c6c6f20776f726c64'
>>> '68656c6c6f20776f726c64'.decode('hex')
'hello world'

For a bcrypt implementation in python, you may want to try py-bcrypt 对于python中的bcrypt实现,您可能需要尝试py-bcrypt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用BCrypt将SQLite数据库中的哈希密码与用户输入进行比较 - Comparing hashed password from SQLite database to user input using BCrypt 在python和java中使用argon2的不同长度的哈希密码 - Different length of hashed password using argon2 in python and java 使用Java验证在PHP中使用password_hash散列的密码 - Using Java to Verify a Password Hashed using password_hash in PHP Spring Security-使用BCrypt哈希密码的用户身份验证(错误的凭证错误) - Spring Security - user authentication with BCrypt hashed password (bad credentials error) 密码编码 - BCrypt - 不授权哈希密码,仅授权纯文本 - Password Encoding - BCrypt - Not Authorising Hashed Passwords, authorising on plain text only Java使用AES和哈希密码作为密钥对图像文件进行加密和解密 - Java encrypting and decryption of image files using AES and a hashed password as key 为LDAP用户设置已经哈希的密码(使用Java) - Set already hashed password for LDAP users (with Java) 检查Java单元测试中是否对密码进行了哈希处理 - Check if a password is hashed in Java Unit test 将哈希密码传递给Java Mail API - Pass hashed password to Java Mail API 如何在android java中使用bcrypt密码散列? - How to use password hashing with bcrypt in android java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM