(String sSrc)
| 29 | } |
| 30 | |
| 31 | public String encrypt(String sSrc) throws Exception { |
| 32 | Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); |
| 33 | byte[] raw = sKey.getBytes(); |
| 34 | SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); |
| 35 | IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes());//使用CBC模式,需要一个向量iv,可增加加密算法的强度 |
| 36 | cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv); |
| 37 | byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8")); |
| 38 | return new String(CBase64.encode(encrypted, CBase64.DEFAULT)); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | public String decrypt(String sSrc) throws Exception { |
no test coverage detected