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


Java DESedeParameters类代码示例

本文整理汇总了Java中org.bouncycastle.crypto.params.DESedeParameters的典型用法代码示例。如果您正苦于以下问题:Java DESedeParameters类的具体用法?Java DESedeParameters怎么用?Java DESedeParameters使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: generateDESKey

import org.bouncycastle.crypto.params.DESedeParameters; //导入依赖的package包/类
/**
 * Generate des key.
 *
 * @param file the file
 * @throws java.io.IOException Signals that an I/O exception has occurred.
 */
public static void generateDESKey(String file) throws IOException {
    DESedeKeyGenerator kg = new DESedeKeyGenerator();
    KeyGenerationParameters kgp = new KeyGenerationParameters(
            new SecureRandom(),
            DESedeParameters.DES_EDE_KEY_LENGTH * 8);
    kg.init(kgp);
    byte[] key = kg.generateKey();
    BufferedOutputStream keystream =
            new BufferedOutputStream(new FileOutputStream(file));
    byte[] keyhex = Hex.encode(key);
    keystream.write(keyhex, 0, keyhex.length);
    keystream.flush();
    keystream.close();
}
 
开发者ID:oneops,项目名称:oneops,代码行数:21,代码来源:CmsCryptoDES.java

示例2: createCipherParameters

import org.bouncycastle.crypto.params.DESedeParameters; //导入依赖的package包/类
static CipherParameters createCipherParameters(ASN1ObjectIdentifier algorithm, ExtendedDigest digest, int blockSize, PKCS12PBEParams pbeParams, char[] password)
{
    PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(digest);

    pGen.init(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password), pbeParams.getIV(), pbeParams.getIterations().intValue());

    CipherParameters params;

    if (PKCS12PBEUtils.hasNoIv(algorithm))
    {
        params = pGen.generateDerivedParameters(PKCS12PBEUtils.getKeySize(algorithm));
    }
    else
    {
        params = pGen.generateDerivedParameters(PKCS12PBEUtils.getKeySize(algorithm), blockSize * 8);

        if (PKCS12PBEUtils.isDesAlg(algorithm))
        {
            DESedeParameters.setOddParity(((KeyParameter)((ParametersWithIV)params).getParameters()).getKey());
        }
    }
    return params;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:24,代码来源:PKCS12PBEUtils.java

示例3: init

import org.bouncycastle.crypto.params.DESedeParameters; //导入依赖的package包/类
/**
 * initialise the key generator - if strength is set to zero
 * the key generated will be 192 bits in size, otherwise
 * strength can be 128 or 192 (or 112 or 168 if you don't count
 * parity bits), depending on whether you wish to do 2-key or 3-key
 * triple DES.
 *
 * @param param the parameters to be used for key generation
 */
public void init(
    KeyGenerationParameters param)
{
    this.random = param.getRandom();
    this.strength = (param.getStrength() + 7) / 8;

    if (strength == 0 || strength == (168 / 8))
    {
        strength = DESedeParameters.DES_EDE_KEY_LENGTH;
    }
    else if (strength == (112 / 8))
    {
        strength = 2 * DESedeParameters.DES_KEY_LENGTH;
    }
    else if (strength != DESedeParameters.DES_EDE_KEY_LENGTH
            && strength != (2 * DESedeParameters.DES_KEY_LENGTH))
    {
        throw new IllegalArgumentException("DESede key must be "
            + (DESedeParameters.DES_EDE_KEY_LENGTH * 8) + " or "
            + (2 * 8 * DESedeParameters.DES_KEY_LENGTH)
            + " bits long.");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:33,代码来源:DESedeKeyGenerator.java

示例4: init

import org.bouncycastle.crypto.params.DESedeParameters; //导入依赖的package包/类
/**
 * initialise the key generator - if strength is set to zero
 * the key generated will be 192 bits in size, otherwise
 * strength can be 128 or 192 (or 112 or 168 if you don't count
 * parity bits), depending on whether you wish to do 2-key or 3-key
 * triple DES.
 *
 * @param param the parameters to be used for key generation
 */
public void init(
    KeyGenerationParameters param)
{
    super.init(param);

    if (strength == 0 || strength == (168 / 8))
    {
        strength = DESedeParameters.DES_EDE_KEY_LENGTH;
    }
    else if (strength == (112 / 8))
    {
        strength = 2 * DESedeParameters.DES_KEY_LENGTH;
    }
    else if (strength != DESedeParameters.DES_EDE_KEY_LENGTH
            && strength != (2 * DESedeParameters.DES_KEY_LENGTH))
    {
        throw new IllegalArgumentException("DESede key must be "
            + (DESedeParameters.DES_EDE_KEY_LENGTH * 8) + " or "
            + (2 * 8 * DESedeParameters.DES_KEY_LENGTH)
            + " bits long.");
    }
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:32,代码来源:DESedeKeyGenerator.java

示例5: create

import org.bouncycastle.crypto.params.DESedeParameters; //导入依赖的package包/类
public static KeyGenerator create() {
  final SecureRandom random = new SecureRandom();
  final KeyGenerationParameters parameters = new KeyGenerationParameters(
      random,
      DESedeParameters.DES_EDE_KEY_LENGTH * 8);
  final DESedeKeyGenerator keyGenerator = new DESedeKeyGenerator();
  keyGenerator.init(parameters);
  return new KeyGenerator(keyGenerator);
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:10,代码来源:KeyGenerator.java

示例6: generateKey

import org.bouncycastle.crypto.params.DESedeParameters; //导入依赖的package包/类
public byte[] generateKey()
{
    byte[]  newKey = new byte[strength];
    int     count = 0;

    do
    {
        random.nextBytes(newKey);

        DESedeParameters.setOddParity(newKey);
    }
    while (++count < MAX_IT && (DESedeParameters.isWeakKey(newKey, 0, newKey.length) || !DESedeParameters.isRealEDEKey(newKey, 0)));

    if (DESedeParameters.isWeakKey(newKey, 0, newKey.length) || !DESedeParameters.isRealEDEKey(newKey, 0))
    {
        throw new IllegalStateException("Unable to generate DES-EDE key");
    }

    return newKey;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:21,代码来源:DESedeKeyGenerator.java

示例7: generateKey

import org.bouncycastle.crypto.params.DESedeParameters; //导入依赖的package包/类
public byte[] generateKey()
{
    byte[]  newKey = new byte[strength];

    do
    {
        random.nextBytes(newKey);

        DESedeParameters.setOddParity(newKey);
    }
    while (DESedeParameters.isWeakKey(newKey, 0, newKey.length));

    return newKey;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:15,代码来源:DESedeKeyGenerator.java

示例8: init

import org.bouncycastle.crypto.params.DESedeParameters; //导入依赖的package包/类
public void init(boolean forEncryption, CipherParameters params)
    throws IllegalArgumentException
{
    byte[] k = Arrays.clone(((KeyParameter)params).getKey());

    DESedeParameters.setOddParity(k);

    if (!Arrays.areEqual(((KeyParameter)params).getKey(), k))
    {
        fail("key not odd parity");
    }

    cipher.init(forEncryption, params);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:15,代码来源:CTRDRBGTest.java


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