use of java.security.spec.AlgorithmParameterSpec in project wicket by apache.
the class SunJceCrypt method crypt.
/**
* Crypts the given byte array
*
* @param input
* byte array to be encrypted
* @param mode
* crypt mode
* @return the input crypted. Null in case of an error
* @throws GeneralSecurityException
*/
@Override
protected byte[] crypt(final byte[] input, final int mode) throws GeneralSecurityException {
SecretKey key = generateSecretKey();
AlgorithmParameterSpec spec = createParameterSpec();
Cipher ciph = createCipher(key, spec, mode);
return ciph.doFinal(input);
}
use of java.security.spec.AlgorithmParameterSpec in project xipki by xipki.
the class KeyUtil method generateRSAKeypair.
// CHECKSTYLE:SKIP
public static KeyPair generateRSAKeypair(int keysize, BigInteger publicExponent, SecureRandom random) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException {
BigInteger tmpPublicExponent = publicExponent;
if (tmpPublicExponent == null) {
tmpPublicExponent = RSAKeyGenParameterSpec.F4;
}
AlgorithmParameterSpec params = new RSAKeyGenParameterSpec(keysize, tmpPublicExponent);
KeyPairGenerator kpGen = getKeyPairGenerator("RSA");
synchronized (kpGen) {
if (random == null) {
kpGen.initialize(params);
} else {
kpGen.initialize(params, random);
}
return kpGen.generateKeyPair();
}
}
use of java.security.spec.AlgorithmParameterSpec in project jeesuite-libs by vakinge.
the class DES method decrypt.
/**
* DES算法,解密
*
* @param data 待解密字符串
* @param key 解密私钥,长度不能够小于8位
* @return 解密后的字节数组
* @throws Exception 异常
*/
public static String decrypt(String key, String data) {
if (data == null)
return null;
try {
DESKeySpec dks = new DESKeySpec(key.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
// key的长度不能够小于8位字节
Key secretKey = keyFactory.generateSecret(dks);
Cipher cipher = Cipher.getInstance(ALGORITHM_DES);
AlgorithmParameterSpec paramSpec = new IvParameterSpec(IV_PARAMS_BYTES);
cipher.init(Cipher.DECRYPT_MODE, secretKey, paramSpec);
return new String(cipher.doFinal(hex2byte(data.getBytes())));
} catch (Exception e) {
e.printStackTrace();
return data;
}
}
use of java.security.spec.AlgorithmParameterSpec in project Bytecoder by mirkosertic.
the class SupportedGroupsExtension method isAvailableGroup.
// check whether the group is supported by the underlying providers
private static boolean isAvailableGroup(NamedGroup namedGroup) {
AlgorithmParameters params = null;
AlgorithmParameterSpec spec = null;
if ("EC".equals(namedGroup.algorithm)) {
if (namedGroup.oid != null) {
try {
params = JsseJce.getAlgorithmParameters("EC");
spec = new ECGenParameterSpec(namedGroup.oid);
} catch (Exception e) {
return false;
}
}
} else if ("DiffieHellman".equals(namedGroup.algorithm)) {
try {
params = JsseJce.getAlgorithmParameters("DiffieHellman");
spec = getFFDHEDHParameterSpec(namedGroup);
} catch (Exception e) {
return false;
}
}
if ((params != null) && (spec != null)) {
try {
params.init(spec);
} catch (Exception e) {
return false;
}
// cache the parameters
namedGroupParams.put(namedGroup, params);
return true;
}
return false;
}
use of java.security.spec.AlgorithmParameterSpec in project santuario-java by apache.
the class DOMCanonicalizationMethod method hashCode.
@Override
public int hashCode() {
int result = 17;
result = 31 * result + getAlgorithm().hashCode();
AlgorithmParameterSpec spec = getParameterSpec();
if (spec != null) {
result = 31 * result + spec.hashCode();
}
return result;
}
Aggregations