Java Code Examples for java.security.spec.AlgorithmParameterSpec

The following are top voted examples for showing how to use java.security.spec.AlgorithmParameterSpec. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openjdk-jdk10   File: Cipher.java   Source Code and License 6 votes vote down vote up
private void checkCryptoPerm(CipherSpi checkSpi, Key key)
        throws InvalidKeyException {
    if (cryptoPerm == CryptoAllPermission.INSTANCE) {
        return;
    }
    // Check if key size and default parameters are within legal limits
    AlgorithmParameterSpec params;
    try {
        params = getAlgorithmParameterSpec(checkSpi.engineGetParameters());
    } catch (InvalidParameterSpecException ipse) {
        throw new InvalidKeyException
            ("Unsupported default algorithm parameters");
    }
    if (!passCryptoPermCheck(checkSpi, key, params)) {
        throw new InvalidKeyException(
            "Illegal key size or default parameters");
    }
}
 
Example 2
Project: Pluto-Android   File: EncryptUtils.java   Source Code and License 6 votes vote down vote up
/**
 * DES算法,加密
 *
 * @param data 待加密字符串
 * @param key  加密私钥,长度不能够小于8位
 * @return 加密后的字节数组,一般结合Base64编码使用
 * @throws InvalidAlgorithmParameterException 
 * @throws Exception 
 */
public static String encode(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);
     IvParameterSpec iv = new IvParameterSpec(key.getBytes());
     AlgorithmParameterSpec paramSpec = iv;
     cipher.init(Cipher.ENCRYPT_MODE, secretKey,paramSpec);           
     byte[] bytes = cipher.doFinal(data.getBytes());            
     return byte2hex(bytes);
	}catch(Exception e){
		e.printStackTrace();
		return data;
	}
}
 
Example 3
Project: OpenJSharp   File: P11TlsPrfGenerator.java   Source Code and License 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (params instanceof TlsPrfParameterSpec == false) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsPrfParameterSpec)params;
    SecretKey key = spec.getSecret();
    if (key == null) {
        key = NULL_KEY;
    }
    try {
        p11Key = P11SecretKeyFactory.convertKey(token, key, null);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException("init() failed", e);
    }
}
 
Example 4
Project: OpenJSharp   File: Cipher.java   Source Code and License 6 votes vote down vote up
private void checkCryptoPerm(CipherSpi checkSpi, Key key,
        AlgorithmParameters params)
        throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (cryptoPerm == CryptoAllPermission.INSTANCE) {
        return;
    }
    // Convert the specified parameters into specs and then delegate.
    AlgorithmParameterSpec pSpec;
    try {
        pSpec = getAlgorithmParameterSpec(params);
    } catch (InvalidParameterSpecException ipse) {
        throw new InvalidAlgorithmParameterException
            ("Failed to retrieve algorithm parameter specification");
    }
    checkCryptoPerm(checkSpi, key, pSpec);
}
 
Example 5
Project: jdk8u-jdk   File: Cipher.java   Source Code and License 6 votes vote down vote up
private AlgorithmParameterSpec getAlgorithmParameterSpec(
                                  AlgorithmParameters params)
        throws InvalidParameterSpecException {
    if (params == null) {
        return null;
    }

    String alg = params.getAlgorithm().toUpperCase(Locale.ENGLISH);

    if (alg.equalsIgnoreCase("RC2")) {
        return params.getParameterSpec(RC2ParameterSpec.class);
    }

    if (alg.equalsIgnoreCase("RC5")) {
        return params.getParameterSpec(RC5ParameterSpec.class);
    }

    if (alg.startsWith("PBE")) {
        return params.getParameterSpec(PBEParameterSpec.class);
    }

    if (alg.startsWith("DES")) {
        return params.getParameterSpec(IvParameterSpec.class);
    }
    return null;
}
 
Example 6
Project: wolfcrypt-jni   File: WolfCryptMac.java   Source Code and License 6 votes vote down vote up
@Override
protected void engineInit(Key key, AlgorithmParameterSpec params)
    throws InvalidKeyException, InvalidAlgorithmParameterException {

    int ret = 0;
    byte[] encodedKey;

    /* key must be of type SecretKey */
    if (!(key instanceof SecretKey))
        throw new InvalidKeyException("Key is not of type SecretKey");

    /* get encoded key */
    encodedKey = key.getEncoded();
    if (encodedKey == null)
        throw new InvalidKeyException("Key does not support encoding");

    this.hmac.setKey(nativeHmacType, encodedKey);

    if (debug.DEBUG)
        log("init with key and spec");
}
 
Example 7
Project: openjdk-jdk10   File: DHKeyPairGenerator.java   Source Code and License 6 votes vote down vote up
/**
 * Initializes this key pair generator for the specified parameter
 * set and source of randomness.
 *
 * <p>The given parameter set contains the prime modulus, the base
 * generator, and optionally the requested size in bits of the random
 * exponent (private value).
 *
 * @param algParams the parameter set used to generate the key pair
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameters
 * are inappropriate for this key pair generator
 */
public void initialize(AlgorithmParameterSpec algParams,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(algParams instanceof DHParameterSpec)){
        throw new InvalidAlgorithmParameterException
            ("Inappropriate parameter type");
    }

    params = (DHParameterSpec)algParams;
    pSize = params.getP().bitLength();
    try {
        checkKeySize(pSize);
    } catch (InvalidParameterException ipe) {
        throw new InvalidAlgorithmParameterException(ipe.getMessage());
    }

    // exponent size is optional, could be 0
    lSize = params.getL();

    // Require exponentSize < primeSize
    if ((lSize != 0) && (lSize > pSize)) {
        throw new InvalidAlgorithmParameterException
            ("Exponent size must not be larger than modulus size");
    }
    this.random = random;
}
 
Example 8
Project: jdk8u-jdk   File: RC2Parameters.java   Source Code and License 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof RC2ParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    RC2ParameterSpec rps = (RC2ParameterSpec) paramSpec;

    // check effective key size (a value of 0 means it is unspecified)
    effectiveKeySize = rps.getEffectiveKeyBits();
    if (effectiveKeySize != 0) {
        if (effectiveKeySize < 1 || effectiveKeySize > 1024) {
            throw new InvalidParameterSpecException("RC2 effective key " +
                "size must be between 1 and 1024 bits");
        }
        if (effectiveKeySize < 256) {
            version = EKB_TABLE[effectiveKeySize];
        } else {
            version = effectiveKeySize;
        }
    }
    this.iv = rps.getIV();
}
 
Example 9
Project: OpenJSharp   File: Cipher.java   Source Code and License 6 votes vote down vote up
private void checkCryptoPerm(CipherSpi checkSpi, Key key)
        throws InvalidKeyException {
    if (cryptoPerm == CryptoAllPermission.INSTANCE) {
        return;
    }
    // Check if key size and default parameters are within legal limits
    AlgorithmParameterSpec params;
    try {
        params = getAlgorithmParameterSpec(checkSpi.engineGetParameters());
    } catch (InvalidParameterSpecException ipse) {
        throw new InvalidKeyException
            ("Unsupported default algorithm parameters");
    }
    if (!passCryptoPermCheck(checkSpi, key, params)) {
        throw new InvalidKeyException(
            "Illegal key size or default parameters");
    }
}
 
Example 10
Project: ipack   File: IESCipher.java   Source Code and License 6 votes vote down vote up
public void engineInit(
    int opmode,
    Key key,
    SecureRandom random)
    throws InvalidKeyException
{
    try
    {
        engineInit(opmode, key, (AlgorithmParameterSpec)null, random);
    }
    catch (InvalidAlgorithmParameterException e)
    {
        throw new IllegalArgumentException("can't handle supplied parameter spec");
    }

}
 
Example 11
Project: openjdk-jdk10   File: DSAParameterGenerator.java   Source Code and License 6 votes vote down vote up
/**
 * Initializes this parameter generator with a set of
 * algorithm-specific parameter generation values.
 *
 * @param genParamSpec the set of algorithm-specific parameter
 *        generation values
 * @param random the source of randomness
 *
 * @exception InvalidAlgorithmParameterException if the given parameter
 * generation values are inappropriate for this parameter generator
 */
@Override
protected void engineInit(AlgorithmParameterSpec genParamSpec,
        SecureRandom random) throws InvalidAlgorithmParameterException {

    if (!(genParamSpec instanceof DSAGenParameterSpec)) {
        throw new InvalidAlgorithmParameterException("Invalid parameter");
    }
    DSAGenParameterSpec dsaGenParams = (DSAGenParameterSpec)genParamSpec;

    // directly initialize using the already validated values
    this.valueL = dsaGenParams.getPrimePLength();
    this.valueN = dsaGenParams.getSubprimeQLength();
    this.seedLen = dsaGenParams.getSeedLength();
    this.random = random;
}
 
Example 12
Project: convertigo-engine   File: Crypto2.java   Source Code and License 6 votes vote down vote up
private Crypto2(String passPhrase) throws InvalidKeySpecException, NoSuchAlgorithmException,
		NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, UnsupportedEncodingException {
	/* Ciphering options:
		Mode = CipherMode.CBC,-( Cipher-block chaining)
		Padding = PaddingMode.PKCS7 or PKCS5,
		KeySize = 128,
		BlockSize = 128,
		Key = keyBytes - password,
		IV = keyBytes  - password
	*/
	
	// Create the key
	byte[] bytesOfMessage = passPhrase.getBytes("UTF-8");
	MessageDigest md = MessageDigest.getInstance("MD5");
	byte[] bytesPassphrase = md.digest(bytesOfMessage);
	SecretKeySpec key = new SecretKeySpec(bytesPassphrase, "AES");
	
    // Parameter specific algorithm
    AlgorithmParameterSpec paramSpec = new IvParameterSpec(bytesPassphrase); 

	ecipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
	ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
	dcipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
	dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
}
 
Example 13
Project: openjdk-jdk10   File: TlsMasterSecretGenerator.java   Source Code and License 6 votes vote down vote up
@SuppressWarnings("deprecation")
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (params instanceof TlsMasterSecretParameterSpec == false) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsMasterSecretParameterSpec)params;
    if ("RAW".equals(spec.getPremasterSecret().getFormat()) == false) {
        throw new InvalidAlgorithmParameterException(
            "Key format must be RAW");
    }
    protocolVersion = (spec.getMajorVersion() << 8)
        | spec.getMinorVersion();
    if ((protocolVersion < 0x0300) || (protocolVersion > 0x0303)) {
        throw new InvalidAlgorithmParameterException(
            "Only SSL 3.0, TLS 1.0/1.1/1.2 supported");
    }
}
 
Example 14
Project: jdk8u-jdk   File: TlsKeyMaterialGenerator.java   Source Code and License 6 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (params instanceof TlsKeyMaterialParameterSpec == false) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsKeyMaterialParameterSpec)params;
    if ("RAW".equals(spec.getMasterSecret().getFormat()) == false) {
        throw new InvalidAlgorithmParameterException(
            "Key format must be RAW");
    }
    protocolVersion = (spec.getMajorVersion() << 8)
        | spec.getMinorVersion();
    if ((protocolVersion < 0x0300) || (protocolVersion > 0x0303)) {
        throw new InvalidAlgorithmParameterException(
            "Only SSL 3.0, TLS 1.0/1.1/1.2 supported");
    }
}
 
Example 15
Project: BiglyBT   File: JDKAlgorithmParameterGenerator.java   Source Code and License 5 votes vote down vote up
@Override
protected void engineInit(
    AlgorithmParameterSpec  genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for IDEA parameter generation.");
}
 
Example 16
Project: jdk8u-jdk   File: SecKFTranslateTest.java   Source Code and License 5 votes vote down vote up
@Override
SecretKey intSecurityKey(AlgorithmParameterSpec[] spec)
        throws InvalidKeySpecException {
    byte[] salt = new byte[8];
    int iterCnt = 6;
    new Random().nextBytes(salt);
    spec[0] = new PBEParameterSpec(salt, iterCnt);
    PBEKeySpec pbeKS = new PBEKeySpec(
            new String("So far so good").toCharArray());
    SecretKey key1 = new MyOwnSecKey(pbeKS);
    return key1;
}
 
Example 17
Project: openjdk-jdk10   File: P11ECDHKeyAgreement.java   Source Code and License 5 votes vote down vote up
protected void engineInit(Key key, AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidKeyException,
        InvalidAlgorithmParameterException {
    if (params != null) {
        throw new InvalidAlgorithmParameterException
                    ("Parameters not supported");
    }
    engineInit(key, random);
}
 
Example 18
Project: openjdk-jdk10   File: GCMParameters.java   Source Code and License 5 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
        T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException {

    if (GCMParameterSpec.class.isAssignableFrom(paramSpec)) {
        return paramSpec.cast(new GCMParameterSpec(tLen * 8, iv));
    } else {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
}
 
Example 19
Project: OpenJSharp   File: TlsRsaPremasterSecretGenerator.java   Source Code and License 5 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsRsaPremasterSecretParameterSpec)params;
    this.random = random;
}
 
Example 20
Project: keepass2android   File: WrapCipherSpi.java   Source Code and License 5 votes vote down vote up
protected void engineInit(
    int                 opmode,
    Key                 key,
    SecureRandom        random)
    throws InvalidKeyException
{
    try
    {
        engineInit(opmode, key, (AlgorithmParameterSpec)null, random);
    }
    catch (InvalidAlgorithmParameterException e)
    {
        throw new IllegalArgumentException(e.getMessage());
    }
}
 
Example 21
Project: keepass2android   File: JCEStreamCipher.java   Source Code and License 5 votes vote down vote up
protected void engineInit(
    int                 opmode,
    Key                 key,
    SecureRandom        random) 
    throws InvalidKeyException
{
    try
    {
        engineInit(opmode, key, (AlgorithmParameterSpec)null, random);
    }
    catch (InvalidAlgorithmParameterException e)
    {
        throw new InvalidKeyException(e.getMessage());
    }
}
 
Example 22
Project: OpenJSharp   File: P11TlsRsaPremasterSecretGenerator.java   Source Code and License 5 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsRsaPremasterSecretParameterSpec)params;
}
 
Example 23
Project: openjdk-jdk10   File: DOMSignatureMethod.java   Source Code and License 5 votes vote down vote up
/**
 * Creates a <code>DOMSignatureMethod</code>.
 *
 * @param params the algorithm-specific params (may be <code>null</code>)
 * @throws InvalidAlgorithmParameterException if the parameters are not
 *    appropriate for this signature method
 */
DOMSignatureMethod(AlgorithmParameterSpec params)
    throws InvalidAlgorithmParameterException
{
    if (params != null &&
        !(params instanceof SignatureMethodParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("params must be of type SignatureMethodParameterSpec");
    }
    checkParams((SignatureMethodParameterSpec)params);
    this.params = (SignatureMethodParameterSpec)params;
}
 
Example 24
Project: letv   File: a.java   Source Code and License 5 votes vote down vote up
public static String a(String str, String str2) {
    AlgorithmParameterSpec ivParameterSpec = new IvParameterSpec(a);
    Key secretKeySpec = new SecretKeySpec(str.getBytes(), "DES");
    Cipher instance = Cipher.getInstance(DEs.ALGORITHM_DES);
    instance.init(1, secretKeySpec, ivParameterSpec);
    return cn.com.iresearch.vvtracker.a.a.a.a(instance.doFinal(str2.getBytes()));
}
 
Example 25
Project: openjdk-jdk10   File: AbstractDOMSignatureMethod.java   Source Code and License 5 votes vote down vote up
@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;
}
 
Example 26
Project: jdk8u-jdk   File: RSAKeyPairGenerator.java   Source Code and License 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params, SecureRandom random)
        throws InvalidAlgorithmParameterException {

    if (params instanceof RSAKeyGenParameterSpec == false) {
        throw new InvalidAlgorithmParameterException
            ("Params must be instance of RSAKeyGenParameterSpec");
    }

    RSAKeyGenParameterSpec rsaSpec = (RSAKeyGenParameterSpec)params;
    int tmpKeySize = rsaSpec.getKeysize();
    BigInteger tmpPublicExponent = rsaSpec.getPublicExponent();

    if (tmpPublicExponent == null) {
        tmpPublicExponent = RSAKeyGenParameterSpec.F4;
    } else {
        if (tmpPublicExponent.compareTo(RSAKeyGenParameterSpec.F0) < 0) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be 3 or larger");
        }
        if (tmpPublicExponent.bitLength() > tmpKeySize) {
            throw new InvalidAlgorithmParameterException
                    ("Public exponent must be smaller than key size");
        }
    }

    // do not allow unreasonably large key sizes, probably user error
    try {
        RSAKeyFactory.checkKeyLengths(tmpKeySize, tmpPublicExponent,
            512, 64 * 1024);
    } catch (InvalidKeyException e) {
        throw new InvalidAlgorithmParameterException(
            "Invalid key sizes", e);
    }

    this.keySize = tmpKeySize;
    this.publicExponent = tmpPublicExponent;
    this.random = random;
}
 
Example 27
Project: ipack   File: McElieceKeyPairGeneratorSpi.java   Source Code and License 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params)
    throws InvalidAlgorithmParameterException
{
    kpg = new McElieceCCA2KeyPairGenerator();
    super.initialize(params);
    ECCKeyGenParameterSpec ecc = (ECCKeyGenParameterSpec)params;

    McElieceCCA2KeyGenerationParameters mccca2KGParams = new McElieceCCA2KeyGenerationParameters(new SecureRandom(), new McElieceCCA2Parameters(ecc.getM(), ecc.getT()));
    kpg.init(mccca2KGParams);
}
 
Example 28
Project: jdk8u-jdk   File: BlockCipherParamsCore.java   Source Code and License 5 votes vote down vote up
void init(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {
    if (!(paramSpec instanceof IvParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    byte[] tmpIv = ((IvParameterSpec)paramSpec).getIV();
    if (tmpIv.length != block_size) {
        throw new InvalidParameterSpecException("IV not " +
                    block_size + " bytes long");
    }
    iv = tmpIv.clone();
}
 
Example 29
Project: jdk8u-jdk   File: KeyPairGenerator.java   Source Code and License 5 votes vote down vote up
public void initialize(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (serviceIterator == null) {
        spi.initialize(params, random);
        return;
    }
    Exception failure = null;
    KeyPairGeneratorSpi mySpi = spi;
    do {
        try {
            mySpi.initialize(params, random);
            initType = I_PARAMS;
            initKeySize = 0;
            initParams = params;
            initRandom = random;
            return;
        } catch (Exception e) {
            if (failure == null) {
                failure = e;
            }
            mySpi = nextSpi(mySpi, false);
        }
    } while (mySpi != null);
    if (failure instanceof RuntimeException) {
        throw (RuntimeException)failure;
    }
    // must be an InvalidAlgorithmParameterException
    throw (InvalidAlgorithmParameterException)failure;
}
 
Example 30
Project: jdk8u-jdk   File: TlsRsaPremasterSecretGenerator.java   Source Code and License 5 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (!(params instanceof TlsRsaPremasterSecretParameterSpec)) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsRsaPremasterSecretParameterSpec)params;
    this.random = random;
}
 
Example 31
Project: ipack   File: AlgorithmParametersSpi.java   Source Code and License 5 votes vote down vote up
protected void engineInit(
    AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException
{
    if (!(paramSpec instanceof IESParameterSpec))
    {
        throw new InvalidParameterSpecException("IESParameterSpec required to initialise a IES algorithm parameters object");
    }

    this.currentSpec = (IESParameterSpec)paramSpec;
}
 
Example 32
Project: alice   File: Alice.java   Source Code and License 5 votes vote down vote up
private AlgorithmParameterSpec getAlgorithmParameterSpec(AliceContext.Mode mode, byte[] initializationVector) {
    switch (mode) {
        case CBC:
        case CTR:
            return new IvParameterSpec(initializationVector);
        case GCM:
            return new GCMParameterSpec(context.getGcmTagLength().bits(), initializationVector);
    }

    throw new IllegalArgumentException("Unknown mode");
}
 
Example 33
Project: xitk   File: P11SM3WithSM2SignatureSpi.java   Source Code and License 5 votes vote down vote up
@Override
protected void engineSetParameter(AlgorithmParameterSpec params)
        throws InvalidAlgorithmParameterException {
    if (params instanceof XiSM2ParameterSpec) {
        paramSpec = (XiSM2ParameterSpec)params;
    } else {
        throw new InvalidAlgorithmParameterException("only XiSM2ParameterSpec supported");
    }
}
 
Example 34
Project: OpenJSharp   File: TlsPrfGenerator.java   Source Code and License 5 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec params,
        SecureRandom random) throws InvalidAlgorithmParameterException {
    if (params instanceof TlsPrfParameterSpec == false) {
        throw new InvalidAlgorithmParameterException(MSG);
    }
    this.spec = (TlsPrfParameterSpec)params;
    SecretKey key = spec.getSecret();
    if ((key != null) && ("RAW".equals(key.getFormat()) == false)) {
        throw new InvalidAlgorithmParameterException(
            "Key encoding format must be RAW");
    }
}
 
Example 35
Project: openjdk-jdk10   File: DOMCanonicalizationMethod.java   Source Code and License 5 votes vote down vote up
@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;
}
 
Example 36
Project: ipack   File: DESede.java   Source Code and License 5 votes vote down vote up
protected void engineInit(
    AlgorithmParameterSpec genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for DES parameter generation.");
}
 
Example 37
Project: ipack   File: PBEPKCS12.java   Source Code and License 5 votes vote down vote up
protected AlgorithmParameterSpec localEngineGetParameterSpec(
    Class paramSpec)
    throws InvalidParameterSpecException
{
    if (paramSpec == PBEParameterSpec.class)
    {
        return new PBEParameterSpec(params.getIV(),
            params.getIterations().intValue());
    }

    throw new InvalidParameterSpecException("unknown parameter spec passed to PKCS12 PBE parameters object.");
}
 
Example 38
Project: ipack   File: PBEPKCS12.java   Source Code and License 5 votes vote down vote up
protected void engineInit(
    AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException
{
    if (!(paramSpec instanceof PBEParameterSpec))
    {
        throw new InvalidParameterSpecException("PBEParameterSpec required to initialise a PKCS12 PBE parameters algorithm parameters object");
    }

    PBEParameterSpec pbeSpec = (PBEParameterSpec)paramSpec;

    this.params = new PKCS12PBEParams(pbeSpec.getSalt(),
        pbeSpec.getIterationCount());
}
 
Example 39
Project: OpenJSharp   File: DSAParameters.java   Source Code and License 5 votes vote down vote up
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {
        if (!(paramSpec instanceof DSAParameterSpec)) {
            throw new InvalidParameterSpecException
                ("Inappropriate parameter specification");
        }
        this.p = ((DSAParameterSpec)paramSpec).getP();
        this.q = ((DSAParameterSpec)paramSpec).getQ();
        this.g = ((DSAParameterSpec)paramSpec).getG();
}
 
Example 40
Project: ipack   File: CAST5.java   Source Code and License 5 votes vote down vote up
protected void engineInit(
    AlgorithmParameterSpec  genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for CAST5 parameter generation.");
}