Search in sources :

Example 71 with AlgorithmParameterSpec

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);
}
Also used : SecretKey(javax.crypto.SecretKey) Cipher(javax.crypto.Cipher) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Example 72 with AlgorithmParameterSpec

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();
    }
}
Also used : BigInteger(java.math.BigInteger) RSAKeyGenParameterSpec(java.security.spec.RSAKeyGenParameterSpec) KeyPairGenerator(java.security.KeyPairGenerator) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Example 73 with AlgorithmParameterSpec

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;
    }
}
Also used : DESKeySpec(javax.crypto.spec.DESKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) SecretKeyFactory(javax.crypto.SecretKeyFactory) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) Key(java.security.Key)

Example 74 with AlgorithmParameterSpec

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;
}
Also used : ECGenParameterSpec(java.security.spec.ECGenParameterSpec) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) SSLProtocolException(javax.net.ssl.SSLProtocolException) IOException(java.io.IOException) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) AlgorithmParameters(java.security.AlgorithmParameters)

Example 75 with AlgorithmParameterSpec

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;
}
Also used : AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec)

Aggregations

AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)173 IvParameterSpec (javax.crypto.spec.IvParameterSpec)56 Cipher (javax.crypto.Cipher)55 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)49 InvalidKeyException (java.security.InvalidKeyException)42 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)37 SecretKey (javax.crypto.SecretKey)27 SecureRandom (java.security.SecureRandom)24 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)24 BadPaddingException (javax.crypto.BadPaddingException)21 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)20 BigInteger (java.math.BigInteger)19 RSAKeyGenParameterSpec (java.security.spec.RSAKeyGenParameterSpec)19 ShortBufferException (javax.crypto.ShortBufferException)19 Key (java.security.Key)18 SecretKeySpec (javax.crypto.spec.SecretKeySpec)18 AlgorithmParameters (java.security.AlgorithmParameters)16 KeyGenerator (javax.crypto.KeyGenerator)16 IOException (java.io.IOException)14 MyCipher (org.apache.harmony.crypto.tests.support.MyCipher)14