JAVA DES / CBC / PKCS5Pad如何将加密翻译成iPhone?

时间:2011-09-14 14:26:46

标签: iphone objective-c des pkcs#5 cbc-mac

源:

public static String encrypt(String src, String key) {
    try {
        Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");

        DESKeySpec dks = new DESKeySpec(key.substring(0, 8).getBytes());

        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
        SecretKey securekey = keyFactory.generateSecret(dks);
        IvParameterSpec iv = new IvParameterSpec(key.substring(0, 8)
                .getBytes());

        cipher.init(Cipher.ENCRYPT_MODE, securekey, iv);
        StringBuilder builder = new StringBuilder();
        byte[] bytes = cipher.doFinal(src.getBytes("UTF-8"));
        for (byte b : bytes) {
            System.out.println(b);
                            builder.append(b);
        }

        return builder.toString().toUpperCase();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}

测试:

System.out.println(encrypt("1995", "ijd.dif*"));

结果:

101 113 87 110 44 8 62 -111

1011138711044862-111

如何将上面的代码转换为客观的c - iPhone?

0 个答案:

没有答案