當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。