Php 使用Python进行openssl密码解密
我使用以下PHP代码加密密码,然后将其保存到数据库中,我需要能够使用Python对其进行解密 我成功地用PHP解密了它,但无法找到它 使用Python实现这一点(如果重要的话,我将使用2.7.9版) 我没有问题打开和读取数据库,我唯一的问题是解密部分。Php 使用Python进行openssl密码解密,php,python,encryption,openssl,encryption-symmetric,Php,Python,Encryption,Openssl,Encryption Symmetric,我使用以下PHP代码加密密码,然后将其保存到数据库中,我需要能够使用Python对其进行解密 我成功地用PHP解密了它,但无法找到它 使用Python实现这一点(如果重要的话,我将使用2.7.9版) 我没有问题打开和读取数据库,我唯一的问题是解密部分。 欢迎提出任何建议,谢谢。终于找到了解决方案。。。下面的代码似乎正在工作,我相信有一种更有效的方法可以做到这一点,但现在它正在做我需要它做的事情。。。希望这将有助于其他人在未来。请记住,这不是保护数据的安全方法 #!/usr/bin/python
欢迎提出任何建议,谢谢。终于找到了解决方案。。。下面的代码似乎正在工作,我相信有一种更有效的方法可以做到这一点,但现在它正在做我需要它做的事情。。。希望这将有助于其他人在未来。请记住,这不是保护数据的安全方法
#!/usr/bin/python
from Crypto.Cipher import AES
import base64
import os
def decryption(encryptedString):
PADDING = '{'
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
#Key is FROM the printout of 'secret' in encryption
#below is the encryption.
encryption = encryptedString
key = "25c6c78835b7479b151f2136cd888777"
cipher = AES.new(key)
decoded = DecodeAES(cipher, encryption)
#print decoded
return decoded
enc_message = "p7OslgBJ5RlTBDG4ZD8HEA" # in my case it will be the data from the database
enc_message = enc_message + "=="
data = decryption(enc_message)
data = data.rstrip()
print data
你试过什么吗?为什么要这样做?加密这样一个密码就像建造一座城堡,然后雇佣一个小男孩来吓唬那些通过吊桥进入的人,一个人被说服在受到攻击时打开吊桥……这有帮助吗?您永远不应该加密用户的密码。您需要使用散列,而一些强散列是PBKDF2、bcrypt、scrypt和Argon2。由于散列函数是单向函数,因此无法“解密”散列。为了对用户进行身份验证,您可以再次通过哈希函数运行密码,以便与存储在数据库中的哈希进行比较。查看更多:
#!/usr/bin/python
from Crypto.Cipher import AES
import base64
import os
def decryption(encryptedString):
PADDING = '{'
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
#Key is FROM the printout of 'secret' in encryption
#below is the encryption.
encryption = encryptedString
key = "25c6c78835b7479b151f2136cd888777"
cipher = AES.new(key)
decoded = DecodeAES(cipher, encryption)
#print decoded
return decoded
enc_message = "p7OslgBJ5RlTBDG4ZD8HEA" # in my case it will be the data from the database
enc_message = enc_message + "=="
data = decryption(enc_message)
data = data.rstrip()
print data