Android Blowfish ECB using Base

2023-02-01  本文已影响0人  嘻嘻哈哈哎呀呀

项目总能遇到各种各样的加密方式,Blowfish ECB + Base64 加密,已验证可直接用

 public static String encodingToBlowfishBase64(String key, String data) {
        try {
            Cipher cipher = Cipher.getInstance("Blowfish/ECB/NoPadding");
            int blockSize = cipher.getBlockSize();
            byte[] dataBytes = data.getBytes();
            int length = dataBytes.length;
            if (length % blockSize != 0) {
                length = length + (blockSize - (length % blockSize));
            }
            byte[] plaintext = new byte[length];
            System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
            SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "Blowfish");
            cipher.init(Cipher.ENCRYPT_MODE, keySpec);
            return Base64.encodeToString(cipher.doFinal(plaintext),Base64.NO_WRAP);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
上一篇 下一篇

猜你喜欢

热点阅读