當前位置: 首頁>>代碼示例>>Java>>正文


Java PBEParameterSpec.getIterationCount方法代碼示例

本文整理匯總了Java中javax.crypto.spec.PBEParameterSpec.getIterationCount方法的典型用法代碼示例。如果您正苦於以下問題:Java PBEParameterSpec.getIterationCount方法的具體用法?Java PBEParameterSpec.getIterationCount怎麽用?Java PBEParameterSpec.getIterationCount使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.crypto.spec.PBEParameterSpec的用法示例。


在下文中一共展示了PBEParameterSpec.getIterationCount方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkParameters

import javax.crypto.spec.PBEParameterSpec; //導入方法依賴的package包/類
private AlgorithmParameters checkParameters(Cipher c, byte[] salt, int iCount)
    throws InvalidParameterSpecException
{
    AlgorithmParameters param = c.getParameters();
    PBEParameterSpec spec = (PBEParameterSpec)param.getParameterSpec(PBEParameterSpec.class);

    if (!Arrays.areEqual(salt, spec.getSalt()))
    {
        fail("" + algorithm + "failed salt test");
    }

    if (iCount != spec.getIterationCount())
    {
        fail("" + algorithm + "failed count test");
    }
    return param;
}
 
開發者ID:NoYouShutup,項目名稱:CryptMeme,代碼行數:18,代碼來源:PBETest.java

示例2: engineInit

import javax.crypto.spec.PBEParameterSpec; //導入方法依賴的package包/類
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());
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:15,代碼來源:PBEPKCS12.java

示例3: engineInit

import javax.crypto.spec.PBEParameterSpec; //導入方法依賴的package包/類
protected void engineInit(
    AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException
{
    if (!(paramSpec instanceof PBEParameterSpec))
    {
        throw new InvalidParameterSpecException("PBEParameterSpec required to initialise a PBKDF2 PBE parameters algorithm parameters object");
    }

    PBEParameterSpec    pbeSpec = (PBEParameterSpec)paramSpec;

    this.params = new PBKDF2Params(pbeSpec.getSalt(),
                        pbeSpec.getIterationCount());
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:15,代碼來源:PBEPBKDF2.java

示例4: CMSPBEKey

import javax.crypto.spec.PBEParameterSpec; //導入方法依賴的package包/類
public CMSPBEKey(char[] password, PBEParameterSpec pbeSpec)
{
    this(password, pbeSpec.getSalt(), pbeSpec.getIterationCount());
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:5,代碼來源:CMSPBEKey.java

示例5: engineInit

import javax.crypto.spec.PBEParameterSpec; //導入方法依賴的package包/類
/**
 * Initializes the HMAC with the given secret key and algorithm parameters.
 *
 * @param key the secret key.
 * @param params the algorithm parameters.
 *
 * @exception InvalidKeyException if the given key is inappropriate for
 * initializing this MAC.
 u* @exception InvalidAlgorithmParameterException if the given algorithm
 * parameters are inappropriate for this MAC.
 */
protected void engineInit(Key key, AlgorithmParameterSpec params)
    throws InvalidKeyException, InvalidAlgorithmParameterException {
    char[] passwdChars;
    byte[] salt = null;
    int iCount = 0;
    if (key instanceof javax.crypto.interfaces.PBEKey) {
        javax.crypto.interfaces.PBEKey pbeKey =
            (javax.crypto.interfaces.PBEKey) key;
        passwdChars = pbeKey.getPassword();
        salt = pbeKey.getSalt(); // maybe null if unspecified
        iCount = pbeKey.getIterationCount(); // maybe 0 if unspecified
    } else if (key instanceof SecretKey) {
        byte[] passwdBytes = key.getEncoded();
        if ((passwdBytes == null) ||
            !(key.getAlgorithm().regionMatches(true, 0, "PBE", 0, 3))) {
            throw new InvalidKeyException("Missing password");
        }
        passwdChars = new char[passwdBytes.length];
        for (int i=0; i<passwdChars.length; i++) {
            passwdChars[i] = (char) (passwdBytes[i] & 0x7f);
        }
    } else {
        throw new InvalidKeyException("SecretKey of PBE type required");
    }
    if (params == null) {
        // generate default for salt and iteration count if necessary
        if (salt == null) {
            salt = new byte[20];
            SunJCE.RANDOM.nextBytes(salt);
        }
        if (iCount == 0) iCount = 100;
    } else if (!(params instanceof PBEParameterSpec)) {
        throw new InvalidAlgorithmParameterException
            ("PBEParameterSpec type required");
    } else {
        PBEParameterSpec pbeParams = (PBEParameterSpec) params;
        // make sure the parameter values are consistent
        if (salt != null) {
            if (!Arrays.equals(salt, pbeParams.getSalt())) {
                throw new InvalidAlgorithmParameterException
                    ("Inconsistent value of salt between key and params");
            }
        } else {
            salt = pbeParams.getSalt();
        }
        if (iCount != 0) {
            if (iCount != pbeParams.getIterationCount()) {
                throw new InvalidAlgorithmParameterException
                    ("Different iteration count between key and params");
            }
        } else {
            iCount = pbeParams.getIterationCount();
        }
    }
    // For security purpose, we need to enforce a minimum length
    // for salt; just require the minimum salt length to be 8-byte
    // which is what PKCS#5 recommends and openssl does.
    if (salt.length < 8) {
        throw new InvalidAlgorithmParameterException
            ("Salt must be at least 8 bytes long");
    }
    if (iCount <= 0) {
        throw new InvalidAlgorithmParameterException
            ("IterationCount must be a positive number");
    }
    byte[] derivedKey = PKCS12PBECipherCore.derive(passwdChars, salt,
        iCount, hmac.getDigestLength(), PKCS12PBECipherCore.MAC_KEY);
    SecretKey cipherKey = new SecretKeySpec(derivedKey, "HmacSHA1");
    hmac.init(cipherKey, null);
}
 
開發者ID:openjdk,項目名稱:jdk7-jdk,代碼行數:82,代碼來源:HmacPKCS12PBESHA1.java


注:本文中的javax.crypto.spec.PBEParameterSpec.getIterationCount方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。