i don't know what i did

This commit is contained in:
hyb1996
2017-09-22 16:12:07 +08:00
parent 23cd6ba6cd
commit 601019cab2
26 changed files with 2354 additions and 13 deletions

View File

@@ -0,0 +1,28 @@
package com.stardust.autojs.runtime.api.crypto;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import static javax.crypto.Cipher.ENCRYPT_MODE;
/**
* Created by Stardust on 2017/9/20.
*/
public class Crypto {
public Cipher createCipher(String algorithm, String password) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException {
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(algorithm);
KeyGenerator keyGenerator = KeyGenerator.getInstance(algorithm);
keyGenerator.init(128, new SecureRandom(password.getBytes()));
SecretKey secretKey = keyGenerator.generateKey();
cipher.init(ENCRYPT_MODE, secretKey);
return cipher;
}
}