[英]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.