本文整理汇总了Java中org.bouncycastle.crypto.PBEParametersGenerator.init方法的典型用法代码示例。如果您正苦于以下问题:Java PBEParametersGenerator.init方法的具体用法?Java PBEParametersGenerator.init怎么用?Java PBEParametersGenerator.init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.PBEParametersGenerator
的用法示例。
在下文中一共展示了PBEParametersGenerator.init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makePBEMacParameters
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/**
* generate a PBE based key suitable for a MAC algorithm, the
* key size is chosen according the MAC size, or the hashing algorithm,
* whichever is greater.
*/
public static CipherParameters makePBEMacParameters(
PBEKeySpec keySpec,
int type,
int hash,
int keySize)
{
PBEParametersGenerator generator = makePBEGenerator(type, hash);
byte[] key;
CipherParameters param;
key = convertPassword(type, keySpec);
generator.init(key, keySpec.getSalt(), keySpec.getIterationCount());
param = generator.generateDerivedMacParameters(keySize);
for (int i = 0; i != key.length; i++)
{
key[i] = 0;
}
return param;
}
示例2: 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);
}
示例3: makePBEMacParameters
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/**
* generate a PBE based key suitable for a MAC algorithm, the
* key size is chosen according the MAC size, or the hashing algorithm,
* whichever is greater.
*/
public static CipherParameters makePBEMacParameters(
BCPBEKey pbeKey,
AlgorithmParameterSpec spec)
{
if ((spec == null) || !(spec instanceof PBEParameterSpec))
{
throw new IllegalArgumentException("Need a PBEParameter spec with a PBE key.");
}
PBEParameterSpec pbeParam = (PBEParameterSpec)spec;
PBEParametersGenerator generator = makePBEGenerator(pbeKey.getType(), pbeKey.getDigest());
byte[] key = pbeKey.getEncoded();
CipherParameters param;
generator.init(key, pbeParam.getSalt(), pbeParam.getIterationCount());
param = generator.generateDerivedMacParameters(pbeKey.getKeySize());
for (int i = 0; i != key.length; i++)
{
key[i] = 0;
}
return param;
}
示例4: 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;
}
示例5: makePBEMacParameters
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/**
* generate a PBE based key suitable for a MAC algorithm, the
* key size is chosen according the MAC size, or the hashing algorithm,
* whichever is greater.
*/
public static CipherParameters makePBEMacParameters(
PBEKeySpec keySpec,
int type,
int hash,
int keySize)
{
PBEParametersGenerator generator = makePBEGenerator(type, hash);
byte[] key;
CipherParameters param;
key = convertPassword(type, keySpec);
generator.init(key, keySpec.getSalt(), keySpec.getIterationCount());
param = generator.generateDerivedMacParameters(keySize);
for (int i = 0; i != key.length; i++)
{
key[i] = 0;
}
return param;
}
示例6: 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;
}
示例7: makePBEMacParameters
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/**
* generate a PBE based key suitable for a MAC algorithm, the
* key size is chosen according the MAC size, or the hashing algorithm,
* whichever is greater.
*/
static CipherParameters makePBEMacParameters(
JCEPBEKey pbeKey,
AlgorithmParameterSpec spec)
{
if ((spec == null) || !(spec instanceof PBEParameterSpec))
{
throw new IllegalArgumentException("Need a PBEParameter spec with a PBE key.");
}
PBEParameterSpec pbeParam = (PBEParameterSpec)spec;
PBEParametersGenerator generator = makePBEGenerator(pbeKey.getType(), pbeKey.getDigest());
byte[] key = pbeKey.getEncoded();
CipherParameters param;
if (pbeKey.shouldTryWrongPKCS12())
{
key = new byte[2];
}
generator.init(key, pbeParam.getSalt(), pbeParam.getIterationCount());
param = generator.generateDerivedMacParameters(pbeKey.getKeySize());
for (int i = 0; i != key.length; i++)
{
key[i] = 0;
}
return param;
}
示例8: 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;
}
示例9: makePBEMacParameters
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
/**
* generate a PBE based key suitable for a MAC algorithm, the
* key size is chosen according the MAC size, or the hashing algorithm,
* whichever is greater.
*/
static CipherParameters makePBEMacParameters(
BCPBEKey pbeKey,
AlgorithmParameterSpec spec,
int type,
int hash,
int keySize)
{
if ((spec == null) || !(spec instanceof PBEParameterSpec))
{
throw new IllegalArgumentException("Need a PBEParameter spec with a PBE key.");
}
PBEParameterSpec pbeParam = (PBEParameterSpec)spec;
PBEParametersGenerator generator = makePBEGenerator(type, hash);
byte[] key = pbeKey.getEncoded();
CipherParameters param;
generator.init(key, pbeParam.getSalt(), pbeParam.getIterationCount());
param = generator.generateDerivedMacParameters(keySize);
for (int i = 0; i != key.length; i++)
{
key[i] = 0;
}
return param;
}
示例10: SingleIterationPBKDF2
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
private static byte[] SingleIterationPBKDF2(byte[] P, byte[] S, int dkLen)
{
PBEParametersGenerator pGen = new PKCS5S2ParametersGenerator(new SHA256Digest());
pGen.init(P, S, 1);
KeyParameter key = (KeyParameter) pGen.generateDerivedMacParameters(dkLen * 8);
return key.getKey();
}
示例11: 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;
}
示例12: generateSecretKeyForPKCS5Scheme2
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
public static SecretKey generateSecretKeyForPKCS5Scheme2(String algorithm, char[] password, byte[] salt, int iterationCount)
{
PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();
generator.init(
PBEParametersGenerator.PKCS5PasswordToBytes(password),
salt,
iterationCount);
return new SecretKeySpec(((KeyParameter)generator.generateDerivedParameters(PEMUtilities.getKeySize(algorithm))).getKey(), algorithm);
}
示例13: 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");
}
}
示例14: 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");
}
}
示例15: run3
import org.bouncycastle.crypto.PBEParametersGenerator; //导入方法依赖的package包/类
private TestResult run3(
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.generateDerivedMacParameters(160);
if (isEqual(result, ((KeyParameter)key).getKey()))
{
return new SimpleTestResult(true, "PKCS12Test: Okay");
}
else
{
return new SimpleTestResult(false, "PKCS12Test: id "
+ id + " Failed");
}
}