• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java OpenSSLPBEParametersGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ObjectMapper类代码示例发布时间:2022-05-22
下一篇:
Java FullWallet类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap