小编Hun*_*rco的帖子

Python Blowfish加密

由于我对Java的不完全了解将这个加密代码转换为Python代码,我正在努力.两者应该具有完全相同的结果.非常感谢帮助.

Java函数

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;


class Main
{
    public static void main (String[] args) throws java.lang.Exception
    {
        String s = "testings";
        Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
        Key key = new SecretKeySpec("6#26FRL$ZWD".getBytes(), "Blowfish");
        cipher.init(1, key);
        byte[] enc_bytes = cipher.doFinal(s.getBytes());
        System.out.println(enc_bytes);
    }
}
Run Code Online (Sandbox Code Playgroud)

Python等价

def PKCS5Padding(string):
    byteNum = len(string)
    packingLength = 8 - byteNum % 8
    if packingLength == 8:
        return string
    else:
        appendage = chr(packingLength) * packingLength
        return string + appendage

def PandoraEncrypt(string):
    from Crypto.Cipher import Blowfish
    key = …
Run Code Online (Sandbox Code Playgroud)

python java encryption blowfish ecb

4
推荐指数
1
解决办法
4519
查看次数

标签 统计

blowfish ×1

ecb ×1

encryption ×1

java ×1

python ×1