use of javax.crypto.SecretKeyFactory in project robovm by robovm.
the class mySecretKeyFactory method testSecretKeyFactory09.
/**
* Test for <code>getInstance(String algorithm, Provider provider)</code>
* method
* Assertion: returns SecretKeyFactory object
*/
public void testSecretKeyFactory09() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
for (int i = 0; i < validValues.length; i++) {
SecretKeyFactory secKF = SecretKeyFactory.getInstance(validValues[i], defaultProvider);
assertEquals("Incorrect algorithm", secKF.getAlgorithm(), validValues[i]);
assertEquals("Incorrect provider", secKF.getProvider(), defaultProvider);
}
}
use of javax.crypto.SecretKeyFactory in project robovm by robovm.
the class mySecretKeyFactory method testSecretKeyFactory03.
/**
* Test for <code>getInstance(String algorithm)</code> method
* Assertion: returns SecretKeyObject
*/
public void testSecretKeyFactory03() throws NoSuchAlgorithmException {
if (!DEFSupported) {
fail(NotSupportMsg);
return;
}
for (int i = 0; i < validValues.length; i++) {
SecretKeyFactory secKF = SecretKeyFactory.getInstance(validValues[i]);
assertEquals("Incorrect algorithm", secKF.getAlgorithm(), validValues[i]);
}
}
use of javax.crypto.SecretKeyFactory in project cobar by alibaba.
the class EncryptUtil method decrypt.
/**
* ????
*
* @param src ????
* @param key ??????????????8?????
* @return ??????????????
* @throws Exception
*/
public static byte[] decrypt(byte[] src, byte[] key) throws Exception {
// DES???????????????��???????
SecureRandom sr = new SecureRandom();
// ????????????????DESKeySpec????
DESKeySpec dks = new DESKeySpec(key);
// ???????????????????????DESKeySpec?????????
// ???SecretKey????
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
// Cipher????????????????
Cipher cipher = Cipher.getInstance(DES);
// ?????????Cipher????
cipher.init(Cipher.DECRYPT_MODE, securekey, sr);
// ?????��??????
return cipher.doFinal(src);
}
use of javax.crypto.SecretKeyFactory in project cobar by alibaba.
the class EncryptUtil method encrypt.
/**
* ????
*
* @param src ????
* @param key ???????????????8
* @return ????????????
* @throws Exception
*/
public static byte[] encrypt(byte[] src, byte[] key) throws Exception {
//DES???????????????��???????
SecureRandom sr = new SecureRandom();
// ?????????????DESKeySpec????
DESKeySpec dks = new DESKeySpec(key);
// ???????????????????????DESKeySpec?????
// ???SecretKey????
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
// Cipher????????????????
Cipher cipher = Cipher.getInstance(DES);
// ?????????Cipher????
cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
// ?????��??????
return cipher.doFinal(src);
}
use of javax.crypto.SecretKeyFactory in project DataX by alibaba.
the class DESCipher method encrypt.
/**
* * 加密
*
* *
*
* * @param src
*
* * 明文(字节)
*
* * @param key
*
* * 密钥,长度必须是8的倍数
*
* * @return 密文(字节)
*
* * @throws Exception
*
*
*/
public static byte[] encrypt(byte[] src, byte[] key) throws Exception {
// DES算法要求有一个可信任的随机数源
SecureRandom sr = new SecureRandom();
// 从原始密匙数据创建DESKeySpec对象
DESKeySpec dks = new DESKeySpec(key);
// 创建一个密匙工厂,然后用它把DESKeySpec转换成
// 一个SecretKey对象
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
SecretKey securekey = keyFactory.generateSecret(dks);
// Cipher对象实际完成加密操作
Cipher cipher = Cipher.getInstance(DES);
// 用密匙初始化Cipher对象
cipher.init(Cipher.ENCRYPT_MODE, securekey, sr);
return cipher.doFinal(src);
}
Aggregations