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


Java PBEParameterSpec類代碼示例

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


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

示例1: calculatePbeMac

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
private static byte[] calculatePbeMac(
    DERObjectIdentifier oid,
    byte[]              salt,
    int                 itCount,
    char[]              password,
    byte[]              data,
    String              provider)
    throws Exception
{
    SecretKeyFactory keyFact = SecretKeyFactory.getInstance(oid.getId(), provider);
    PBEParameterSpec defParams = new PBEParameterSpec(salt, itCount);
    PBEKeySpec pbeSpec = new PBEKeySpec(password);
    SecretKey key = keyFact.generateSecret(pbeSpec);

    Mac mac = Mac.getInstance(oid.getId(), provider);
    mac.init(key, defParams);
    mac.update(data);

    return mac.doFinal();
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:21,代碼來源:PKCS12Util.java

示例2: makePBECipher

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
protected Cipher makePBECipher(
    String  algorithm,
    int     mode,
    char[]  password,
    byte[]  salt,
    int     iterationCount)
    throws IOException
{
    try
    {
        PBEKeySpec          pbeSpec = new PBEKeySpec(password);
        SecretKeyFactory    keyFact = SecretKeyFactory.getInstance(algorithm, BouncyCastleProvider.PROVIDER_NAME);
        PBEParameterSpec    defParams = new PBEParameterSpec(salt, iterationCount);

        Cipher cipher = Cipher.getInstance(algorithm, BouncyCastleProvider.PROVIDER_NAME);

        cipher.init(mode, keyFact.generateSecret(pbeSpec), defParams);

        return cipher;
    }
    catch (Exception e)
    {
        throw new IOException("Error initialising store of key store: " + e);
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:26,代碼來源:BcKeyStoreSpi.java

示例3: cryptData

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
protected byte[] cryptData(
    boolean forEncryption,
    AlgorithmIdentifier algId,
    char[] password,
    boolean wrongPKCS12Zero,
    byte[] data)
    throws IOException
{
    String algorithm = algId.getAlgorithm().getId();
    PKCS12PBEParams pbeParams = PKCS12PBEParams.getInstance(algId.getParameters());
    PBEKeySpec pbeSpec = new PBEKeySpec(password);

    try
    {
        SecretKeyFactory keyFact = SecretKeyFactory.getInstance(algorithm, bcProvider);
        PBEParameterSpec defParams = new PBEParameterSpec(
            pbeParams.getIV(),
            pbeParams.getIterations().intValue());
        BCPBEKey key = (BCPBEKey)keyFact.generateSecret(pbeSpec);

        key.setTryWrongPKCS12Zero(wrongPKCS12Zero);

        Cipher cipher = Cipher.getInstance(algorithm, bcProvider);
        int mode = forEncryption ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE;
        cipher.init(mode, key, defParams);
        return cipher.doFinal(data);
    }
    catch (Exception e)
    {
        throw new IOException("exception decrypting data - " + e.toString());
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:33,代碼來源:PKCS12KeyStoreSpi.java

示例4: calculatePbeMac

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
private static byte[] calculatePbeMac(
    ASN1ObjectIdentifier oid,
    byte[] salt,
    int itCount,
    char[] password,
    boolean wrongPkcs12Zero,
    byte[] data)
    throws Exception
{
    SecretKeyFactory keyFact = SecretKeyFactory.getInstance(oid.getId(), bcProvider);
    PBEParameterSpec defParams = new PBEParameterSpec(salt, itCount);
    PBEKeySpec pbeSpec = new PBEKeySpec(password);
    BCPBEKey key = (BCPBEKey)keyFact.generateSecret(pbeSpec);
    key.setTryWrongPKCS12Zero(wrongPkcs12Zero);

    Mac mac = Mac.getInstance(oid.getId(), bcProvider);
    mac.init(key, defParams);
    mac.update(data);
    return mac.doFinal();
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:21,代碼來源:PKCS12KeyStoreSpi.java

示例5: getAlgorithmParameters

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
private AlgorithmParameters getAlgorithmParameters(String algorithm)
    throws IOException
{
    AlgorithmParameters algParams = null;

    // create PBE parameters from salt and iteration count
    PBEParameterSpec paramSpec =
            new PBEParameterSpec(getSalt(), iterationCount);
    try {
       algParams = AlgorithmParameters.getInstance(algorithm);
       algParams.init(paramSpec);
    } catch (Exception e) {
       throw new IOException("getAlgorithmParameters failed: " +
                             e.getMessage(), e);
    }
    return algParams;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:PKCS12KeyStore.java

示例6: setUp

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
private void setUp() {
    out.println("Using KEYSTORE_PATH:"+KEYSTORE_PATH);
    Utils.createKeyStore(Utils.KeyStoreType.pkcs12, KEYSTORE_PATH, ALIAS);
    Random rand = RandomFactory.getRandom();
    rand.nextBytes(SALT);
    out.print("Salt: ");
    for (byte b : SALT) {
        out.format("%02X ", b);
    }
    out.println("");
    PASSWORD_PROTECTION
            .add(new KeyStore.PasswordProtection(PASSWORD,
                            "PBEWithMD5AndDES", new PBEParameterSpec(SALT,
                                    ITERATION_COUNT)));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndDESede", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC2_128", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_40", null));
    PASSWORD_PROTECTION.add(new KeyStore.PasswordProtection(PASSWORD,
            "PBEWithSHA1AndRC4_128", null));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:EntryProtectionTest.java

示例7: getCipherFromPassphrase

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
private static Cipher getCipherFromPassphrase(String passphrase, byte[] salt, int iterations, int opMode)
    throws GeneralSecurityException
{
  SecretKey key    = getKeyFromPassphrase(passphrase, salt, iterations);
  Cipher    cipher = Cipher.getInstance(key.getAlgorithm());
  cipher.init(opMode, key, new PBEParameterSpec(salt, iterations));

  return cipher;
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:10,代碼來源:MasterSecretUtil.java

示例8: encriptar

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
public static String encriptar(String passPhrase, String str)
    throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException
{
    Cipher ecipher = null;
    Cipher dcipher = null;
    java.security.spec.KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), SALT_BYTES, ITERATION_COUNT);
    SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
    ecipher = Cipher.getInstance(key.getAlgorithm());
    dcipher = Cipher.getInstance(key.getAlgorithm());
    java.security.spec.AlgorithmParameterSpec paramSpec = new PBEParameterSpec(SALT_BYTES, ITERATION_COUNT);
    ecipher.init(1, key, paramSpec);
    dcipher.init(2, key, paramSpec);
    byte utf8[] = str.getBytes("UTF8");
    byte enc[] = ecipher.doFinal(utf8);
    return (new BASE64Encoder()).encode(enc);
}
 
開發者ID:marlonalexis,項目名稱:Multicentro_Mascotas,代碼行數:17,代碼來源:UtilCryptography.java

示例9: desencriptar

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
public static String desencriptar(String passPhrase, String str)
    throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IOException, IllegalBlockSizeException, BadPaddingException
{
    Cipher ecipher = null;
    Cipher dcipher = null;
    java.security.spec.KeySpec keySpec = new PBEKeySpec(passPhrase.toCharArray(), SALT_BYTES, ITERATION_COUNT);
    SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
    ecipher = Cipher.getInstance(key.getAlgorithm());
    dcipher = Cipher.getInstance(key.getAlgorithm());
    java.security.spec.AlgorithmParameterSpec paramSpec = new PBEParameterSpec(SALT_BYTES, ITERATION_COUNT);
    ecipher.init(1, key, paramSpec);
    dcipher.init(2, key, paramSpec);
    byte dec[] = (new BASE64Decoder()).decodeBuffer(str);
    byte utf8[] = dcipher.doFinal(dec);
    return new String(utf8, "UTF8");
}
 
開發者ID:marlonalexis,項目名稱:Multicentro_Mascotas,代碼行數:17,代碼來源:UtilCryptography.java

示例10: encrypt

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
/**
 * 加密明文字符串
 *
 * @param plaintext
 *            待加密的明文字符串
 * @param password
 *            生成密鑰時所使用的密碼
 * @param salt
 *            鹽值
 * @return 加密後的密文字符串
 * @throws Exception
 */
public static String encrypt(String plaintext, String password, byte[] salt) {

    Key key = getPBEKey(password);
    byte[] encipheredData = null;
    PBEParameterSpec parameterSpec = new PBEParameterSpec(salt, ITERATIONCOUNT);
    try {
        Cipher cipher = Cipher.getInstance(ALGORITHM);

        cipher.init(Cipher.ENCRYPT_MODE, key, parameterSpec);

        encipheredData = cipher.doFinal(plaintext.getBytes());
    } catch (Exception e) {
    }
    return bytesToHexString(encipheredData);
}
 
開發者ID:haizicq,項目名稱:osframe,代碼行數:28,代碼來源:PasswordUtil.java

示例11: decrypt

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
/**
 * 解密密文字符串
 *
 * @param ciphertext
 *            待解密的密文字符串
 * @param password
 *            生成密鑰時所使用的密碼(如需解密,該參數需要與加密時使用的一致)
 * @param salt
 *            鹽值(如需解密,該參數需要與加密時使用的一致)
 * @return 解密後的明文字符串
 * @throws Exception
 */
public static String decrypt(String ciphertext, String password, byte[] salt) {

    Key key = getPBEKey(password);
    byte[] passDec = null;
    PBEParameterSpec parameterSpec = new PBEParameterSpec(getStaticSalt(), ITERATIONCOUNT);
    try {
        Cipher cipher = Cipher.getInstance(ALGORITHM);

        cipher.init(Cipher.DECRYPT_MODE, key, parameterSpec);

        passDec = cipher.doFinal(hexStringToBytes(ciphertext));
    }

    catch (Exception e) {
        // TODO: handle exception
    }
    return new String(passDec);
}
 
開發者ID:haizicq,項目名稱:osframe,代碼行數:31,代碼來源:PasswordUtil.java

示例12: buildCipher

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
/**
 * Builds the java cipher using the BouncyCastle crypto library)
 *
 * @param encryptMode Cipher.DECRYPT_MODE or Cipher.ENCRYPT_MODE
 * @return the AES256 encrypt or decrypt cipher
 * @throws InvalidKeySpecException if the key specification is invalid
 * @throws InvalidAlgorithmParameterException if the algorithm is not supported
 * @throws InvalidKeyException if the key is invalid
 * @throws NoSuchAlgorithmException if the encryption system fails
 * @throws NoSuchPaddingException if the algorithm padding parameter is not supported
 */
private static Cipher buildCipher(int encryptMode) throws InvalidKeySpecException, InvalidAlgorithmParameterException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException {
    //Create the key specification
    PBEParameterSpec pbeParamSpec = new PBEParameterSpec(ENCRYPTION_SALT, ENCRYPTION_ITERATION_COUNT);
    PBEKeySpec pbeKeySpec = new PBEKeySpec(ENCRYPTION_PASSPHRASE);

    //Configure the key
    SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(ENCRYPTION_ALGORITHM);
    SecretKey secretKey = secretKeyFactory.generateSecret(pbeKeySpec);

    //Initialise the cipher
    Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
    cipher.init(encryptMode, secretKey, pbeParamSpec);

    return cipher;
}
 
開發者ID:AlexisChevalier,項目名稱:CarRental-Distributed-System,代碼行數:27,代碼來源:CryptoUtils.java

示例13: encrypt

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
/**
 * 加密明文字符串
 * 
 * @param plaintext
 *            待加密的明文字符串
 * @param password
 *            生成密鑰時所使用的密碼
 * @param salt
 *            鹽值
 * @return 加密後的密文字符串
 * @throws Exception
 */
public static String encrypt(String plaintext, String password, byte[] salt) {

	Key key = getPBEKey(password);
	byte[] encipheredData = null;
	PBEParameterSpec parameterSpec = new PBEParameterSpec(salt, ITERATIONCOUNT);
	try {
		Cipher cipher = Cipher.getInstance(ALGORITHM);

		cipher.init(Cipher.ENCRYPT_MODE, key, parameterSpec);

		encipheredData = cipher.doFinal(plaintext.getBytes());
	} catch (Exception e) {
	}
	return bytesToHexString(encipheredData);
}
 
開發者ID:tzou24,項目名稱:abina-common-util,代碼行數:28,代碼來源:PasswordUtils.java

示例14: decrypt

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
/**
 * 解密密文字符串
 * 
 * @param ciphertext
 *            待解密的密文字符串
 * @param password
 *            生成密鑰時所使用的密碼(如需解密,該參數需要與加密時使用的一致)
 * @param salt
 *            鹽值(如需解密,該參數需要與加密時使用的一致)
 * @return 解密後的明文字符串
 * @throws Exception
 */
public static String decrypt(String ciphertext, String password, byte[] salt) {

	Key key = getPBEKey(password);
	byte[] passDec = null;
	PBEParameterSpec parameterSpec = new PBEParameterSpec(getStaticSalt(), ITERATIONCOUNT);
	try {
		Cipher cipher = Cipher.getInstance(ALGORITHM);

		cipher.init(Cipher.DECRYPT_MODE, key, parameterSpec);

		passDec = cipher.doFinal(hexStringToBytes(ciphertext));
	}

	catch (Exception e) {
		// TODO: handle exception
	}
	return new String(passDec);
}
 
開發者ID:tzou24,項目名稱:abina-common-util,代碼行數:31,代碼來源:PasswordUtils.java

示例15: getPBEAlgorithmParameters

import javax.crypto.spec.PBEParameterSpec; //導入依賴的package包/類
private AlgorithmParameters getPBEAlgorithmParameters(String algorithm)
    throws IOException
{
    AlgorithmParameters algParams = null;

    // create PBE parameters from salt and iteration count
    PBEParameterSpec paramSpec =
            new PBEParameterSpec(getSalt(), PBE_ITERATION_COUNT);
    try {
       algParams = AlgorithmParameters.getInstance(algorithm);
       algParams.init(paramSpec);
    } catch (Exception e) {
       throw new IOException("getPBEAlgorithmParameters failed: " +
                             e.getMessage(), e);
    }
    return algParams;
}
 
開發者ID:ojdkbuild,項目名稱:lookaside_java-1.8.0-openjdk,代碼行數:18,代碼來源:PKCS12KeyStore.java


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