叶测试 - 类库
type: channel
link: https://r1989.com/tag/%E7%B1%BB%E5%BA%93/
items: 安卓端JAVA AES加密对应处理类
items: APP开发AES加密 PHP后台类库

安卓端JAVA AES加密对应处理类
type: item
date: 2017-10-30T08:00:00+00:00
description: // // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // package com.wiggins.teaching.utils; import android.util.Base64; import java.io.UnsupportedEncodingException; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; public class AESHelper { private static final String CipherMode = "AES/ECB/PKCS5Padding"; private static final String password = "Coding@xxx.China"; public AESHelper() { } private static SecretKeySpec createKey(String password) { byte[] data = null; if(password == null) { password = ""; } StringBuffer sb = new StringBuffer(16); sb.append(password); while(sb.length() < 16) { sb.append("0"); } if(sb.length() > 16) { sb.setLength(16); } try { data = sb.toString().getBytes("UTF-8"); } catch (UnsupportedEncodingException var4) { var4.printStackTrace(); } return new SecretKeySpec(data, "AES"); } public static byte[] encrypt(byte[] content, String password) { try { SecretKeySpec e = createKey(password); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(1, e); byte[] result = cipher.doFinal(content); return result; } catch (Exception var5) { var5.printStackTrace(); return null; } } public static String encrypt(String content, String password) { byte[] data = null; try { data = content.getBytes("UTF-8"); } catch (Exception var4) { var4.printStackTrace(); } data = encrypt(data, password); String result = Base64.encodeToString(data, 2); return result; } public static String encrypt(String content) { byte[] data = null; try { data = content.getBytes("UTF-8"); } catch (Exception var3) { var3.printStackTrace(); } data = encrypt(data, "sgg45747ss223455"); String result = Base64.encodeToString(data, 2); return result; } public static byte[] decrypt(byte[] content, String password) { try { SecretKeySpec e = createKey(password); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(2, e); byte[] result = cipher.doFinal(content); return result; } catch (Exception var5)…

APP开发AES加密 PHP后台类库
type: item
date: 2017-10-30T07:52:00+00:00
description: <?php namespace icecry; /** * aes 加密 解密类库 * @by singwa */ class Aes { private $key = null; /** * * @param $key 密钥 * @return String */ public function __construct() { $this->key = 'Coding@xxx.China'; } /** * 加密 * @param String input 加密的字符串 * @param String key 解密的key * @return HexString */ public function encrypt($input = '') { $size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB); $input = $this->pkcs5_pad($input, $size); $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_ECB, ''); $iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_RAND); mcrypt_generic_init($td, $this->key, $iv); $data = mcrypt_generic($td, $input); mcrypt_generic_deinit($td); mcrypt_module_close($td); $data = base64_encode($data); return $data; } /** * 填充方式 pkcs5 * @param String text 原始字符串 * @param String blocksize 加密长度 * @return String */ private function pkcs5_pad($text, $blocksize) { $pad = $blocksize - (strlen($text) % $blocksize); return $text . str_repeat(chr($pad), $pad); } /** * 解密 * @param String input 解密的字符串 * @param String key 解密的key * @return String */ public function decrypt($sStr) { $decrypted= mcrypt_decrypt(MCRYPT_RIJNDAEL_128,$this->key,base64_decode($sStr), MCRYPT_MODE_ECB); $dec_s = strlen($decrypted); $padding = ord($decrypted[$dec_s-1]); $decrypted = substr($decrypted, 0, -$padding); return $decrypted; } }