开发者

JAVA DES/CBC/PKCS5Padding how encryption translated into iPhone?

source:

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 "";
}

Test:

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

result:

101 113 87 110 44 8 62 -111

1011138711044862-111

How the code above into objective c - iPhone?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜