当前位置: 首页>>代码示例>>Java>>正文


Java AlgorithmParameterSpec类代码示例

本文整理汇总了Java中java.security.spec.AlgorithmParameterSpec的典型用法代码示例。如果您正苦于以下问题:Java AlgorithmParameterSpec类的具体用法?Java AlgorithmParameterSpec怎么用?Java AlgorithmParameterSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AlgorithmParameterSpec类属于java.security.spec包,在下文中一共展示了AlgorithmParameterSpec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkCryptoPerm

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Cipher.java

示例2: encode

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
/**
 * 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;
	}
}
 
开发者ID:PlutoArchitecture,项目名称:Pluto-Android,代码行数:29,代码来源:EncryptUtils.java

示例3: engineInit

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
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);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:P11TlsPrfGenerator.java

示例4: checkCryptoPerm

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:Cipher.java

示例5: getAlgorithmParameterSpec

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:Cipher.java

示例6: engineInit

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
@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");
}
 
开发者ID:wolfSSL,项目名称:wolfcrypt-jni,代码行数:22,代码来源:WolfCryptMac.java

示例7: initialize

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:DHKeyPairGenerator.java

示例8: engineInit

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
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();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:RC2Parameters.java

示例9: engineInit

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
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");
    }

}
 
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:IESCipher.java

示例10: engineInit

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:DSAParameterGenerator.java

示例11: Crypto2

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
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);
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:26,代码来源:Crypto2.java

示例12: engineInit

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
@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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:TlsMasterSecretGenerator.java

示例13: engineInit

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
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");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:TlsKeyMaterialGenerator.java

示例14: engineInit

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
@Override
protected void engineInit(
    AlgorithmParameterSpec  genParamSpec,
    SecureRandom            random)
    throws InvalidAlgorithmParameterException
{
    throw new InvalidAlgorithmParameterException("No supported AlgorithmParameterSpec for IDEA parameter generation.");
}
 
开发者ID:BiglySoftware,项目名称:BiglyBT,代码行数:9,代码来源:JDKAlgorithmParameterGenerator.java

示例15: intSecurityKey

import java.security.spec.AlgorithmParameterSpec; //导入依赖的package包/类
@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;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:SecKFTranslateTest.java


注:本文中的java.security.spec.AlgorithmParameterSpec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。