我有一個隨機特殊字符(它已被更改)的鹽漬解密密鑰:J_a&[email protected]$0=f%4{4-f-1*1([email protected]&e|0)1&987*5([email protected]$1'1(4*0)1}c+f'[email protected]@8_6_c)[email protected]@c(3}
我需要刪除所有特殊字符並返回它的未加鹽版本,例如,現在我使用:更安全的方法從已解密的密鑰中除去salt
def remove_salt(decrypted_key):
""" Remove salt from a decrypted key """
invalid_chars = set(string.punctuation)
return_key = []
for c in decrypted_key:
if c not in invalid_chars:
return_key.append(c)
return ''.join(return_key)
因此,這將是這樣的:
>>> remove_salt("J_a&[email protected]$0=f%4{4-f-1*1([email protected]&e|0)1&987*5([email protected]$1'1(4*0)1}c+f'[email protected]@8_6_c)[email protected]@c(3}")
'Ja30000f44f111d03e019875b12311401cf59d86c41c3'
>>>
是沒有辦法,我可以取消導航鍵的鹽沒有完全揭示鹽是什麼更安全的方式,我的意思是string.punctuation
明確指出,那個無效的char行動者是[email protected]#$ .. etc
。如何在不完全揭示我的鹽是什麼的情況下去除這種鹽?
請注意,這是鹽漬的方式不是我的選擇。我只需要把這個東西放在一個不漏鹽的地方,而不需要注意鹽是什麼。
您可以改爲使用'invalid_chars'作爲參數。如果這仍然不是你在那之後,我會建議有一個外部文件,用於讀取和使用無效字符。你也可以將你的代碼壓縮到'return''.join(如果c不在invalid_chars中,c代表解密密鑰中的c)' –
鹽不是祕密信息,所以你不需要隱藏它。我建議你看看標準的加密庫。 – msitt
不安全!=安全。這不是如何醃製 – Dan