使用在https://raw.github.com/usefulfor/usefulfor/master/security/JBoss.java找到的代碼編碼的,我做了以下幾部件:河豚解密通過javax.crypto中
bash-3.2$ java -cp . JBoss -e testpython
-27038292d345798947e2852756afcf0a
bash-3.2$ java -cp . JBoss -d -27038292d345798947e2852756afcf0a
testpython
但是,我不能爲我的生命,弄清楚如何解密字符串'27038292d345798947e2852756afcf0a'在python中使用pycrypto。我的理解是,Java代碼使用Blowfish,而'jaas'是'密碼'的關鍵。但我無法理解如何在python中做到這一點。以下結果主要是不可打印的垃圾:
import Crypto
from Crypto.Cipher import Blowfish
from base64 import b64encode, b64decode
bs = Blowfish.block_size
key = 'jaas is the way'
plaintext = b'27038292d345798947e2852756afcf0a'
iv = '\0' * 8
c1 = Blowfish.new(key, Blowfish.MODE_ECB)
c2 = Blowfish.new(key, Blowfish.MODE_CBC, iv)
c3 = Blowfish.new(key, Blowfish.MODE_CFB, iv)
c4 = Blowfish.new(key, Blowfish.MODE_OFB, iv)
msg1 = c1.decrypt(plaintext)
msg2 = c2.decrypt(plaintext)
msg3 = c3.decrypt(plaintext)
msg4 = c4.decrypt(plaintext)
print "msg1 = %s\n" % msg1
print "msg2 = %s\n" % msg2
print "msg3 = %s\n" % msg3
print "msg4 = %s\n" % msg4
我錯過了什麼?
謝謝。
歡迎SO!確保您將答案標記爲答案旁邊的複選框。 – jterrace