美文网首页
Android Blowfish ECB using Base

Android Blowfish ECB using Base

作者: 嘻嘻哈哈哎呀呀 | 来源:发表于2023-02-01 10:17 被阅读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;
        }
    }

相关文章

网友评论

      本文标题:Android Blowfish ECB using Base

      本文链接:https://www.haomeiwen.com/subject/oukihdtx.html