如何将河豚解密从python移植到java?

2024-09-30 12:21:41 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有一个python2漏洞破解:

from Crypto.Cipher import Blowfish

decodee = '1234'
key = 'oY3[r.Ri4oF'
IV = '\x00\x00\x00\x00\x00\x00\x00\x00'

res = Blowfish.new(key=key, mode=Blowfish.MODE_CFB, IV=IV).decrypt(decodee)
print len(res), map(ord, list(res))

带输出

^{pr2}$

我试着像这样将它移植到java:

String decodee = "1234";
String key = "oY3[r.Ri4oF";
String iv = "\0\0\0\0\0\0\0\0";

SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "Blowfish");
IvParameterSpec ivSpec = new IvParameterSpec(iv.getBytes());

Cipher cipher = Cipher.getInstance("Blowfish/CFB/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);

byte[] res = cipher.doFinal(decodee.getBytes());
String s = new String(res);  
int[] x = new int[s.length()]; for (int i = 0 ; i < s.length() ; i++) x[i] = (int) s.charAt(i);
System.out.println(Arrays.toString(x));

但它显示:

4 [124, 242, 10, 112]

如何使它相等?在


Tags: keynewstringmoderesintcipherx00

热门问题