本文整理汇总了Java中org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator类的典型用法代码示例。如果您正苦于以下问题:Java OpenSSLPBEParametersGenerator类的具体用法?Java OpenSSLPBEParametersGenerator怎么用?Java OpenSSLPBEParametersGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OpenSSLPBEParametersGenerator类属于org.bouncycastle.crypto.generators包,在下文中一共展示了OpenSSLPBEParametersGenerator类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getKey
import org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator; //导入依赖的package包/类
private static SecretKey getKey(
char[] password,
String algorithm,
int keyLength,
byte[] salt,
boolean des2)
throws IOException
{
OpenSSLPBEParametersGenerator pGen = new OpenSSLPBEParametersGenerator();
pGen.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt);
KeyParameter keyParam;
keyParam = (KeyParameter) pGen.generateDerivedParameters(keyLength * 8);
byte[] key = keyParam.getKey();
if (des2 && key.length >= 24)
{
// For DES2, we must copy first 8 bytes into the last 8 bytes.
System.arraycopy(key, 0, key, 16, 8);
}
return new javax.crypto.spec.SecretKeySpec(key, algorithm);
}
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:23,代码来源:PEMUtilities.java
示例2: getKey
import org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator; //导入依赖的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: getKey
import org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator; //导入依赖的package包/类
private static SecretKey getKey(
char[] password,
String algorithm,
int keyLength,
byte[] salt,
boolean des2)
{
OpenSSLPBEParametersGenerator pGen = new OpenSSLPBEParametersGenerator();
pGen.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt);
KeyParameter keyParam;
keyParam = (KeyParameter) pGen.generateDerivedParameters(keyLength * 8);
byte[] key = keyParam.getKey();
if (des2 && key.length >= 24)
{
// For DES2, we must copy first 8 bytes into the last 8 bytes.
System.arraycopy(key, 0, key, 16, 8);
}
return new SecretKeySpec(key, algorithm);
}
开发者ID:credentials,项目名称:irma_future_id,代码行数:22,代码来源:PEMUtilities.java
示例4: getKey
import org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator; //导入依赖的package包/类
private static SecretKey getKey(
char[] password,
String algorithm,
int keyLength,
byte[] salt,
boolean des2)
{
OpenSSLPBEParametersGenerator pGen = new OpenSSLPBEParametersGenerator();
pGen.init(PBEParametersGenerator.PKCS5PasswordToBytes(password), salt);
KeyParameter keyParam;
keyParam = (KeyParameter)pGen.generateDerivedParameters(keyLength * 8);
byte[] key = keyParam.getKey();
if (des2 && key.length >= 24)
{
// For DES2, we must copy first 8 bytes into the last 8 bytes.
System.arraycopy(key, 0, key, 16, 8);
}
return new javax.crypto.spec.SecretKeySpec(key, algorithm);
}
开发者ID:credentials,项目名称:irma_future_id,代码行数:22,代码来源:PEMReader.java
示例5: engineGenerateSecret
import org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator; //导入依赖的package包/类
protected SecretKey engineGenerateSecret(
KeySpec keySpec)
throws InvalidKeySpecException
{
if (keySpec instanceof PBEKeySpec)
{
PBEKeySpec pbeSpec = (PBEKeySpec)keySpec;
if (pbeSpec.getSalt() == null)
{
throw new InvalidKeySpecException("missing required salt");
}
if (pbeSpec.getIterationCount() <= 0)
{
throw new InvalidKeySpecException("positive iteration count required: "
+ pbeSpec.getIterationCount());
}
if (pbeSpec.getKeyLength() <= 0)
{
throw new InvalidKeySpecException("positive key length required: "
+ pbeSpec.getKeyLength());
}
if (pbeSpec.getPassword().length == 0)
{
throw new IllegalArgumentException("password empty");
}
OpenSSLPBEParametersGenerator pGen = new OpenSSLPBEParametersGenerator();
pGen.init(Strings.toByteArray(pbeSpec.getPassword()), pbeSpec.getSalt());
return new SecretKeySpec(((KeyParameter)pGen.generateDerivedParameters(pbeSpec.getKeyLength())).getKey(), "OpenSSLPBKDF");
}
throw new InvalidKeySpecException("Invalid KeySpec");
}
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:40,代码来源:OpenSSLPBKDF.java
示例6: generate
import org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator; //导入依赖的package包/类
/** {@inheritDoc} */
public byte[] generate(final char[] password, final int size) {
final OpenSSLPBEParametersGenerator generator = new OpenSSLPBEParametersGenerator();
generator.init(PBEParametersGenerator.PKCS5PasswordToBytes(password),
salt);
final KeyParameter p = (KeyParameter) generator
.generateDerivedParameters(size);
return p.getKey();
}
开发者ID:shivam091,项目名称:Java-Security,代码行数:11,代码来源:OpenSSLKeyGenerator.java
示例7: performTest
import org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator; //导入依赖的package包/类
public void performTest()
throws Exception
{
byte[] salt = new byte[16];
int iCount = 100;
for (int i = 0; i != salt.length; i++)
{
salt[i] = (byte)i;
}
OpenSSLPBEParametersGenerator pGen = new OpenSSLPBEParametersGenerator();
pGen.init(
PBEParametersGenerator.PKCS5PasswordToBytes(password),
salt,
iCount);
ParametersWithIV params = (ParametersWithIV)pGen.generateDerivedParameters(keySize, ivSize);
SecretKeySpec encKey = new SecretKeySpec(((KeyParameter)params.getParameters()).getKey(), baseAlgorithm);
Cipher c;
if (baseAlgorithm.equals("RC4"))
{
c = Cipher.getInstance(baseAlgorithm, "BC");
c.init(Cipher.ENCRYPT_MODE, encKey);
}
else
{
c = Cipher.getInstance(baseAlgorithm + "/CBC/PKCS7Padding", "BC");
c.init(Cipher.ENCRYPT_MODE, encKey, new IvParameterSpec(params.getIV()));
}
byte[] enc = c.doFinal(salt);
c = Cipher.getInstance(algorithm, "BC");
PBEKeySpec keySpec = new PBEKeySpec(password, salt, iCount);
SecretKeyFactory fact = SecretKeyFactory.getInstance(algorithm, "BC");
c.init(Cipher.DECRYPT_MODE, fact.generateSecret(keySpec));
byte[] dec = c.doFinal(enc);
if (!Arrays.areEqual(salt, dec))
{
fail("" + algorithm + "failed encryption/decryption test");
}
}
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:54,代码来源:PBETest.java
示例8: perform
import org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator; //导入依赖的package包/类
public TestResult perform()
{
byte[] salt = new byte[16];
int iCount = 100;
for (int i = 0; i != salt.length; i++)
{
salt[i] = (byte)i;
}
try
{
OpenSSLPBEParametersGenerator pGen = new OpenSSLPBEParametersGenerator();
pGen.init(
PBEParametersGenerator.PKCS5PasswordToBytes(password),
salt);
ParametersWithIV params = (ParametersWithIV)pGen.generateDerivedParameters(keySize, ivSize);
SecretKeySpec encKey = new SecretKeySpec(((KeyParameter)params.getParameters()).getKey(), baseAlgorithm);
Cipher c;
if (baseAlgorithm.equals("RC4"))
{
c = Cipher.getInstance(baseAlgorithm, "BC");
c.init(Cipher.ENCRYPT_MODE, encKey);
}
else
{
c = Cipher.getInstance(baseAlgorithm + "/CBC/PKCS7Padding", "BC");
c.init(Cipher.ENCRYPT_MODE, encKey, new IvParameterSpec(params.getIV()));
}
byte[] enc = c.doFinal(salt);
c = Cipher.getInstance(algorithm, "BC");
PBEKeySpec keySpec = new PBEKeySpec(password);
SecretKeyFactory fact = SecretKeyFactory.getInstance(algorithm, "BC");
c.init(Cipher.DECRYPT_MODE, fact.generateSecret(keySpec), new PBEParameterSpec(salt, iCount));
byte[] dec = c.doFinal(enc);
if (!arrayEquals(salt, dec))
{
return new SimpleTestResult(false, getName() + ": " + algorithm + "failed encryption/decryption test");
}
return new SimpleTestResult(true, getName() + ": Okay");
}
catch (Exception e)
{
return new SimpleTestResult(false, getName() + ": " + algorithm + " failed - exception " + e, e);
}
}
开发者ID:credentials,项目名称:irma_future_id,代码行数:60,代码来源:PBETest.java
示例9: getKeyParamWithIv
import org.bouncycastle.crypto.generators.OpenSSLPBEParametersGenerator; //导入依赖的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.generators.OpenSSLPBEParametersGenerator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论