小程序敏感信息解密-java

    /**  
     * AES解密  
     * @param content 密文  
     * @return  
     * @throws InvalidAlgorithmParameterException   
     * @throws NoSuchProviderException   
     */    
    public static byte[] xcx_decrypt(byte[] content, byte[] keyByte, byte[] ivByte) throws InvalidAlgorithmParameterException {    
        initialize();    
        try {    
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");    
            Key sKeySpec = new SecretKeySpec(keyByte, "AES");    
                
            cipher.init(Cipher.DECRYPT_MODE, sKeySpec, generateIV(ivByte));// 初始化     
            byte[] result = cipher.doFinal(content);    
            return result;    
        } catch (NoSuchAlgorithmException e) {    
            e.printStackTrace();      
        } catch (NoSuchPaddingException e) {    
            e.printStackTrace();      
        } catch (InvalidKeyException e) {    
            e.printStackTrace();    
        } catch (IllegalBlockSizeException e) {    
            e.printStackTrace();    
        } catch (BadPaddingException e) {    
            e.printStackTrace();    
        } catch (NoSuchProviderException e) {    
            // TODO Auto-generated catch block    
            e.printStackTrace();    
        } catch (Exception e) {    
            // TODO Auto-generated catch block    
            e.printStackTrace();    
        }    
        return null;    
    } 

调用方式:

	public static void main(String[] args) throws Exception {
		byte[] resultByte = AES.xcx_decrypt(Base64.decodeBase64(reqInfoJSONObject.getString("encryptedData")),
				Base64.decodeBase64("sessionKey"), Base64.decodeBase64(reqInfoJSONObject.getString("iv")));
		String userInfo = new String(resultByte, "UTF-8");
		JSONObject userObj = JSONObject.fromObject(userInfo);
		logger.info("userInfo ===>" + userInfo);
		URLEncoder.encode(userObj.getString("nickName"), "utf-8");
		userObj.getString("unionId");

	}

 

转载于:https://www.cnblogs.com/fanyu666/p/8952750.html

你可能感兴趣的:(小程序敏感信息解密-java)