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


Java PBEParametersGenerator.generateDerivedParameters方法代码示例

本文整理汇总了Java中org.bouncycastle.crypto.PBEParametersGenerator.generateDerivedParameters方法的典型用法代码示例。如果您正苦于以下问题:Java PBEParametersGenerator.generateDerivedParameters方法的具体用法?Java PBEParametersGenerator.generateDerivedParameters怎么用?Java PBEParametersGenerator.generateDerivedParameters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.crypto.PBEParametersGenerator的用法示例。


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

示例1: compareModes

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
@Test
public void compareModes() {
    BlockCipher engine = new AESEngine();
    int blockSize = engine.getBlockSize();
    BlockCipher ref = new SICBlockCipher(engine); // reference implementation
    BlockCipher uut = new CtrBlockCipher(engine); // unit under test
    PBEParametersGenerator gen = new PKCS5S2ParametersGenerator();
    byte[] salt = new byte[blockSize]; // used as salt and cipher input
    new SecureRandom().nextBytes(salt);
    gen.init("top secret".getBytes(), salt, 1);
    ParametersWithIV
            param = (ParametersWithIV) gen.generateDerivedParameters(
                blockSize * 8,
                blockSize * 8);

    ref.init(true, param);
    uut.init(true, param);
    assertModes(ref, uut);

    ref.init(false, param);
    uut.init(false, param);
    assertModes(ref, uut);
}
 
开发者ID:christian-schlichtherle,项目名称:truevfs,代码行数:24,代码来源:CtrBlockCipherTest.java

示例2: getKey

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
private static KeyParameter getKey(
    char[]  password,
    int     keyLength,
    byte[]  salt,
    boolean des2)
    throws PEMException
{
    PBEParametersGenerator paramsGen = new OpenSSLPBEParametersGenerator();

    paramsGen.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt, 1);

    KeyParameter kp = (KeyParameter)paramsGen.generateDerivedParameters(keyLength * 8);

    if (des2 && kp.getKey().length == 24)
    {
        // For DES2, we must copy first 8 bytes into the last 8 bytes.
        byte[] key = kp.getKey();

        System.arraycopy(key, 0, key, 16, 8);

        return new KeyParameter(key);
    }

    return kp;
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:26,代码来源:PEMUtilities.java

示例3: crypt

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
private static byte[] crypt(final boolean encrypt, final byte[] bytes, final String password, final byte[] salt) throws InvalidCipherTextException {
    final PBEParametersGenerator keyGenerator = new PKCS12ParametersGenerator(new SHA256Digest());
    keyGenerator.init(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password.toCharArray()), salt, 20);
    final CipherParameters keyParams = keyGenerator.generateDerivedParameters(256, 128);

    final BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), new PKCS7Padding());
    cipher.init(encrypt, keyParams);

    final byte[] processed = new byte[cipher.getOutputSize(bytes.length)];
    int outputLength = cipher.processBytes(bytes, 0, bytes.length, processed, 0);
    outputLength += cipher.doFinal(processed, outputLength);

    final byte[] results = new byte[outputLength];
    System.arraycopy(processed, 0, results, 0, outputLength);
    return results;
}
 
开发者ID:Kloudtek,项目名称:kloudmake,代码行数:17,代码来源:AESHelper.java

示例4: makePBEParameters

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/**
 * construct a key and iv (if necessary) suitable for use with a 
 * Cipher.
 */
static CipherParameters makePBEParameters(
    PBEKeySpec              keySpec,
    int                     type,
    int                     hash,
    int                     keySize,
    int                     ivSize)
{    
    PBEParametersGenerator  generator = makePBEGenerator(type, hash);
    byte[]                  key;
    CipherParameters        param;
    
    if (type == PKCS12)
    {
        key = PBEParametersGenerator.PKCS12PasswordToBytes(keySpec.getPassword());
    }
    else
    {   
        key = PBEParametersGenerator.PKCS5PasswordToBytes(keySpec.getPassword());
    }
    
    generator.init(key, keySpec.getSalt(), keySpec.getIterationCount());
    
    if (ivSize != 0)
    {
        param = generator.generateDerivedParameters(keySize, ivSize);
    }
    else
    {
        param = generator.generateDerivedParameters(keySize);
    }
    
    for (int i = 0; i != key.length; i++)
    {
        key[i] = 0;
    }
    
    return param;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:43,代码来源:PBE.java

示例5: makePBEParameters

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/**
 * construct a key and iv (if necessary) suitable for use with a 
 * Cipher.
 */
public static CipherParameters makePBEParameters(
    PBEKeySpec keySpec,
    int type,
    int hash,
    int keySize,
    int ivSize)
{    
    PBEParametersGenerator  generator = makePBEGenerator(type, hash);
    byte[]                  key;
    CipherParameters        param;

    key = convertPassword(type, keySpec);

    generator.init(key, keySpec.getSalt(), keySpec.getIterationCount());
    
    if (ivSize != 0)
    {
        param = generator.generateDerivedParameters(keySize, ivSize);
    }
    else
    {
        param = generator.generateDerivedParameters(keySize);
    }
    
    for (int i = 0; i != key.length; i++)
    {
        key[i] = 0;
    }
    
    return param;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:36,代码来源:PBE.java

示例6: run1

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
private TestResult run1(
    int     id,
    char[]  password,
    byte[]  salt,
    int     iCount,
    byte[]  result)
{
    PBEParametersGenerator  generator = new PKCS12ParametersGenerator(
                                                new SHA1Digest());

    generator.init(
            PBEParametersGenerator.PKCS12PasswordToBytes(password),
            salt,
            iCount);

    CipherParameters  key = generator.generateDerivedParameters(24 * 8);

    if (isEqual(result, ((KeyParameter)key).getKey()))
    {
        return new SimpleTestResult(true, "PKCS12Test: Okay");
    }
    else
    {
        return new SimpleTestResult(false, "PKCS12Test: id "
                                                + id + " Failed");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:28,代码来源:PKCS12Test.java

示例7: run2

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
private TestResult run2(
    int     id,
    char[]  password,
    byte[]  salt,
    int     iCount,
    byte[]  result)
{
    PBEParametersGenerator  generator = new PKCS12ParametersGenerator(
                                                new SHA1Digest());

    generator.init(
            PBEParametersGenerator.PKCS12PasswordToBytes(password),
            salt,
            iCount);

    ParametersWithIV params = (ParametersWithIV)generator.generateDerivedParameters(64, 64);

    if (isEqual(result, params.getIV()))
    {
        return new SimpleTestResult(true, "PKCS12Test: Okay");
    }
    else
    {
        return new SimpleTestResult(false, "PKCS12Test: id "
                                                + id + " Failed");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:28,代码来源:PKCS12Test.java

示例8: generate

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
@Override
public byte[] generate(String password, int length) {
	PBEParametersGenerator gen = new PKCS12ParametersGenerator(digester);
	gen.init(PBEParametersGenerator.PKCS12PasswordToBytes(password.toCharArray()), salt, iteration);
	KeyParameter param = (KeyParameter) gen.generateDerivedParameters(length);
	return param.getKey();
}
 
开发者ID:shilongdai,项目名称:vsDiaryWriter,代码行数:8,代码来源:BCPCKDF2Generator.java

示例9: generateSecretKeyForPKCS5Scheme2

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
public static KeyParameter generateSecretKeyForPKCS5Scheme2(String algorithm, char[] password, byte[] salt, int iterationCount)
{
    PBEParametersGenerator paramsGen = new PKCS5S2ParametersGenerator(new SHA1Digest());

    paramsGen.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt, iterationCount);

    return (KeyParameter)paramsGen.generateDerivedParameters(PEMUtilities.getKeySize(algorithm));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:9,代码来源:PEMUtilities.java

示例10: init

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
public void init( String pwStr, int keySize, byte[] salt, byte[] pwVerification ) throws ZipException {
	byte[] pwBytes = pwStr.getBytes();
	
	super.saltBytes = salt;

	PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();
	generator.init( pwBytes, salt, ITERATION_COUNT );

	cipherParameters = generator.generateDerivedParameters(KEY_SIZE_BIT*2 + 16);
	byte[] keyBytes = ((KeyParameter)cipherParameters).getKey();

	this.cryptoKeyBytes = new byte[ KEY_SIZE_BYTE ];
	System.arraycopy( keyBytes, 0, cryptoKeyBytes, 0, KEY_SIZE_BYTE );

	this.authenticationCodeBytes = new byte[ KEY_SIZE_BYTE ];
	System.arraycopy( keyBytes, KEY_SIZE_BYTE, authenticationCodeBytes, 0, KEY_SIZE_BYTE );

	// based on SALT + PASSWORD (password is probably correct)
	this.pwVerificationBytes = new byte[ 2 ];
	System.arraycopy( keyBytes, KEY_SIZE_BYTE*2, this.pwVerificationBytes, 0, 2 );

	if( !ByteArrayHelper.isEqual( this.pwVerificationBytes, pwVerification ) ) {
		throw new ZipException("wrong password - " + ByteArrayHelper.toString(this.pwVerificationBytes) + "/ " + ByteArrayHelper.toString(pwVerification));
	}

	// create the first 16 bytes of the key sequence again (using pw+salt)
	generator.init( pwBytes, salt, ITERATION_COUNT );
	cipherParameters = generator.generateDerivedParameters(KEY_SIZE_BIT);

	// checksum added to the end of the encrypted data, update on each encryption call
	this.mac = new HMac( new SHA1Digest() );
	mac.init( new KeyParameter(authenticationCodeBytes) );

	this.aesCipher = new SICBlockCipher(new AESEngine());
	this.blockSize = aesCipher.getBlockSize();

	// incremented on each 16 byte block and used as encryption NONCE (ivBytes)
	nonce = 1;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:40,代码来源:AESDecrypterBC.java

示例11: generate

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/** {@inheritDoc} */
public byte[] generate(final char[] password, final int size) {
	if (size < 1) {
		throw new IllegalArgumentException("Size must be positive integer.");
	}

	final PBEParametersGenerator generator = newParamGenerator();
	generator.init(toBytes(password), salt, iterationCount);

	final KeyParameter p = (KeyParameter) generator
			.generateDerivedParameters(size);
	return p.getKey();
}
 
开发者ID:shivam091,项目名称:Java-Security,代码行数:14,代码来源:AbstractPKCSKeyGenerator.java

示例12: newKey

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
@Override
public ByteArray newKey(DerivedKeyParams keyParams) throws EncryptionException {
    PBEParametersGenerator gen = new PKCS5S2ParametersGenerator(new SHA1Digest());
    gen.init(keyParams.getPassword(), keyParams.getSalt(), keyParams.getIterations());
    KeyParameter keyParam = (KeyParameter) gen.generateDerivedParameters(keyParams.getKeySize());
    return new ByteArray(keyParam.getKey());
}
 
开发者ID:d1x,项目名称:dxcrypto,代码行数:8,代码来源:BouncyCastlePBKDF2KeyFactory.java

示例13: init

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/**
 * Setup AES encryption based on pwBytes using WinZipAES approach
 * with SALT and pwVerification bytes based on password+salt.
 */
public void init( String pwStr, int keySize ) throws ZipException {
	byte[] pwBytes = pwStr.getBytes();
	PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();
	this.saltBytes = createSalt();
	generator.init( pwBytes, saltBytes, ITERATION_COUNT );

	// create 2 byte[16] for two keys and one byte[2] for pwVerification
	// 1. encryption / 2. athentication (via HMAC/hash) /
	cipherParameters = generator.generateDerivedParameters(KEY_SIZE_BIT*2 + 16);
	byte[] keyBytes = ((KeyParameter)cipherParameters).getKey();

	this.cryptoKeyBytes = new byte[ KEY_SIZE_BYTE ];
	System.arraycopy( keyBytes, 0, cryptoKeyBytes, 0, KEY_SIZE_BYTE );

	this.authenticationCodeBytes = new byte[ KEY_SIZE_BYTE ];
	System.arraycopy( keyBytes, KEY_SIZE_BYTE, authenticationCodeBytes, 0, KEY_SIZE_BYTE );

	// based on SALT + PASSWORD (password is probably correct)
	this.pwVerificationBytes = new byte[ 2 ];
	System.arraycopy( keyBytes, KEY_SIZE_BYTE*2, pwVerificationBytes, 0, 2 );

	// create the first 16 bytes of the key sequence again (using pw+salt)
	generator.init( pwBytes, saltBytes, ITERATION_COUNT );
	cipherParameters = generator.generateDerivedParameters(KEY_SIZE_BIT);

	// checksum added to the end of the encrypted data, update on each encryption call
	this.mac = new HMac( new SHA1Digest() );
	mac.init( new KeyParameter(authenticationCodeBytes) );

	this.aesCipher = new SICBlockCipher(new AESEngine());
	this.blockSize = aesCipher.getBlockSize();

	// incremented on each 16 byte block and used as encryption NONCE (ivBytes)
	nonce = 1;
	
	if( LOG.isLoggable(Level.FINEST) ) {
		LOG.finest( "pwBytes   = " + ByteArrayHelper.toString(pwBytes) + " - " + pwBytes.length );
		LOG.finest( "salt      = " + ByteArrayHelper.toString(saltBytes) + " - " + saltBytes.length );
		LOG.finest( "pwVerif   = " + ByteArrayHelper.toString(pwVerificationBytes) + " - " + pwVerificationBytes.length );
	}
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:46,代码来源:AESEncrypterBC.java

示例14: BcPasswordBasedKey

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
public BcPasswordBasedKey(char[] password, int keySize, int iterations, byte[] salt) {
    PBEParametersGenerator keyGenerator = new PKCS5S2ParametersGenerator();
    byte[] pkcsPasswordBytes = PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(password);
    keyGenerator.init(pkcsPasswordBytes, salt, iterations);
    this.secretKey = (KeyParameter) keyGenerator.generateDerivedParameters(keySize);
}
 
开发者ID:dzhemriza,项目名称:toffi,代码行数:7,代码来源:BcPasswordBasedKey.java

示例15: getKeyParamWithIv

import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
private static ParametersWithIV getKeyParamWithIv(String keyphrase, byte[] salt, int aes_bit) {
  int iterationCount = 1;
  PBEParametersGenerator generator = new OpenSSLPBEParametersGenerator();
  generator.init(PBEParametersGenerator.PKCS5PasswordToBytes(keyphrase.toCharArray()), salt, iterationCount);
  return (ParametersWithIV) generator.generateDerivedParameters(aes_bit, 128);
}
 
开发者ID:miguelsm,项目名称:droidklavier,代码行数:7,代码来源:Crypto.java


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