开发者社区> 问答> 正文

关于IOS易宝充值接口AES/ECB/PKCS5Padding算法加密问题

有谁做过易宝IOS充值接口?现在我出现的问题是加密了,易宝那边解析不了,有人能帮我解决下么?
高分补偿!!

补充一下是128位的不是256的加密

展开
收起
爵霸 2016-03-13 09:23:31 2822 0
1 条回答
写回答
取消 提交回答
  • 试试看:

    private static final String SECRET_AES = "AES";
        private static final String SECRET_PATTERN_ECB = "AES/ECB/PKCS5Padding";
        private static final String CODE = "UTF-8";
        private static Cipher cipher;
        private static SecretKeySpec secretKey;
    
        /***
         * AES加密
         * 
         * @param value
         * @param key
         * @return
         */
        public static byte[] _encode(String value, String key) {
            try {
                byte[] bs = key.getBytes(CODE);
                secretKey = new SecretKeySpec(bs, SECRET_AES);
                cipher = Cipher.getInstance(SECRET_PATTERN_ECB);
                cipher.init(Cipher.ENCRYPT_MODE, secretKey);
                return cipher.doFinal(value.getBytes(CODE));
            } catch (Exception e) {
                return null;
            }
        }
    
        /***
         * AES解密
         * 
         * @param value
         * @param key
         * @return
         */
        public static String _decode(byte[] value, String key) {
            try {
                byte[] bs = key.getBytes(CODE);
                secretKey = new SecretKeySpec(bs, SECRET_AES);
                cipher = Cipher.getInstance(SECRET_PATTERN_ECB);
                cipher.init(Cipher.DECRYPT_MODE, secretKey);
                byte[] decrypt = cipher.doFinal(value);
                return new String(decrypt);
            } catch (Exception e) {
                return null;
            }
        }
    
    2019-07-17 19:01:43
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
手淘iOS性能优化探索 立即下载
From Java/Android to Swift iOS 立即下载
深入剖析iOS性能优化 立即下载