MCPcopy Create free account
hub / github.com/SeanDragon/protools / encrypt

Method encrypt

security/src/main/java/pro/tools/security/ToolAES.java:106–121  ·  view source on GitHub ↗

加密 @param data 待加密数据 @param key 密钥 @return byte[] 加密数据 @throws Exception

(byte[] data, byte[] key)

Source from the content-addressed store, hash-verified

104 * @throws Exception
105 */
106 public static byte[] encrypt(byte[] data, byte[] key) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
107 // 还原密钥
108 Key k = toKey(key);
109
110 /*
111 * 实例化 使用PKCS7Padding填充方式,按如下方式实现 Cipher.getInstance(CIPHER_ALGORITHM,
112 * "BC");
113 */
114 Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM);
115
116 // 初始化,设置为加密模式
117 cipher.init(Cipher.ENCRYPT_MODE, k);
118
119 // 执行操作
120 return cipher.doFinal(data);
121 }
122
123 /**
124 * 生成密钥 <br>

Callers

nothing calls this directly

Calls 3

toKeyMethod · 0.95
getInstanceMethod · 0.80
initMethod · 0.45

Tested by

no test coverage detected