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

Method encrypt

security/src/main/java/pro/tools/security/ToolPBE.java:109–126  ·  view source on GitHub ↗

加密 @param data 数据 @param password 密码 @param salt 盐 @return byte[] 加密数据 @throws Exception

(byte[] data, String password, byte[] salt)

Source from the content-addressed store, hash-verified

107 * @throws Exception
108 */
109 public static byte[] encrypt(byte[] data, String password, byte[] salt) throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidAlgorithmParameterException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
110
111 // 转换密钥
112 Key key = toKey(password);
113
114 // 实例化PBE参数材料
115 PBEParameterSpec paramSpec = new PBEParameterSpec(salt, HASH_BIT_SIZE);
116
117 // 实例化
118 Cipher cipher = Cipher.getInstance(ALGORITHM);
119
120 // 初始化
121 cipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
122
123 // 执行操作
124 return cipher.doFinal(data);
125
126 }
127
128 /**
129 * 解密

Callers

nothing calls this directly

Calls 3

toKeyMethod · 0.95
getInstanceMethod · 0.80
initMethod · 0.45

Tested by

no test coverage detected