當前位置: 首頁>>代碼示例>>Java>>正文


Java KeyParameter類代碼示例

本文整理匯總了Java中org.bouncycastle.crypto.params.KeyParameter的典型用法代碼示例。如果您正苦於以下問題:Java KeyParameter類的具體用法?Java KeyParameter怎麽用?Java KeyParameter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


KeyParameter類屬於org.bouncycastle.crypto.params包,在下文中一共展示了KeyParameter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: determineKeyEncAlg

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
static AlgorithmIdentifier determineKeyEncAlg(KeyParameter key)
{
    int length = key.getKey().length * 8;
    ASN1ObjectIdentifier wrapOid;

    if (length == 128)
    {
        wrapOid = NISTObjectIdentifiers.id_aes128_wrap;
    }
    else if (length == 192)
    {
        wrapOid = NISTObjectIdentifiers.id_aes192_wrap;
    }
    else if (length == 256)
    {
        wrapOid = NISTObjectIdentifiers.id_aes256_wrap;
    }
    else
    {
        throw new IllegalArgumentException("illegal keysize in AES");
    }

    return new AlgorithmIdentifier(wrapOid); // parameters absent
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:25,代碼來源:AESUtil.java

示例2: init

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
/**
 * initialise a Twofish cipher.
 *
 * @param encrypting whether or not we are for encryption.
 * @param params the parameters required to set up the cipher.
 * @exception IllegalArgumentException if the params argument is
 * inappropriate.
 */
public void init(
    boolean             encrypting,
    CipherParameters    params)
{
    if (params instanceof KeyParameter)
    {
        this.encrypting = encrypting;
        this.workingKey = ((KeyParameter)params).getKey();
        this.k64Cnt = (this.workingKey.length / 8); // pre-padded ?
        setKey(this.workingKey);

        return;
    }

    throw new IllegalArgumentException("invalid parameter passed to Twofish init - " + params.getClass().getName());
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:25,代碼來源:TwofishEngine.java

示例3: extractSecretKey

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
protected KeyParameter extractSecretKey(AlgorithmIdentifier keyEncryptionAlgorithm, AlgorithmIdentifier contentEncryptionAlgorithm, byte[] derivedKey, byte[] encryptedContentEncryptionKey)
    throws CMSException
{
    Wrapper keyEncryptionCipher = EnvelopedDataHelper.createRFC3211Wrapper(keyEncryptionAlgorithm.getAlgorithm());

    keyEncryptionCipher.init(false, new ParametersWithIV(new KeyParameter(derivedKey), ASN1OctetString.getInstance(keyEncryptionAlgorithm.getParameters()).getOctets()));

    try
    {
        return new KeyParameter(keyEncryptionCipher.unwrap(encryptedContentEncryptionKey, 0, encryptedContentEncryptionKey.length));
    }
    catch (InvalidCipherTextException e)
    {
        throw new CMSException("unable to unwrap key: " + e.getMessage(), e);
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:17,代碼來源:BcPasswordRecipient.java

示例4: generateDerivedParameters

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
/**
 * Generate a key with initialisation vector parameter derived from
 * the password, salt, and iteration count we are currently initialised
 * with.
 *
 * @param keySize the size of the key we want (in bits)
 * @param ivSize the size of the iv we want (in bits)
 * @return a ParametersWithIV object.
 * @exception IllegalArgumentException if keySize + ivSize is larger than the base hash size.
 */
public CipherParameters generateDerivedParameters(
    int     keySize,
    int     ivSize)
{
    keySize = keySize / 8;
    ivSize = ivSize / 8;

    if ((keySize + ivSize) > digest.getDigestSize())
    {
        throw new IllegalArgumentException(
               "Can't generate a derived key " + (keySize + ivSize) + " bytes long.");
    }

    byte[]  dKey = generateDerivedKey();

    return new ParametersWithIV(new KeyParameter(dKey, 0, keySize), dKey, keySize, ivSize);
}
 
開發者ID:PhilippC,項目名稱:keepass2android,代碼行數:28,代碼來源:PKCS5S1ParametersGenerator.java

示例5: determineKeyEncAlg

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
static AlgorithmIdentifier determineKeyEncAlg(KeyParameter key)
{
    int length = key.getKey().length * 8;
    ASN1ObjectIdentifier wrapOid;

    if (length == 128)
    {
        wrapOid = NTTObjectIdentifiers.id_camellia128_wrap;
    }
    else if (length == 192)
    {
        wrapOid = NTTObjectIdentifiers.id_camellia192_wrap;
    }
    else if (length == 256)
    {
        wrapOid = NTTObjectIdentifiers.id_camellia256_wrap;
    }
    else
    {
        throw new IllegalArgumentException(
            "illegal keysize in Camellia");
    }

    return new AlgorithmIdentifier(wrapOid); // parameters must be
    // absent
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:27,代碼來源:CamelliaUtil.java

示例6: createCipherParameters

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的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

示例7: init

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
/**
 * initialise an ISAAC cipher.
 *
 * @param forEncryption whether or not we are for encryption.
 * @param params the parameters required to set up the cipher.
 * @exception IllegalArgumentException if the params argument is
 * inappropriate.
 */
public void init(
    boolean             forEncryption, 
    CipherParameters    params)
{
    if (!(params instanceof KeyParameter))
    {
        throw new IllegalArgumentException("invalid parameter passed to ISAAC init - " + params.getClass().getName());
    }
    /* 
     * ISAAC encryption and decryption is completely
     * symmetrical, so the 'forEncryption' is 
     * irrelevant.
     */
    KeyParameter p = (KeyParameter)params;
    setKey(p.getKey());
    
    return;
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:27,代碼來源:ISAACEngine.java

示例8: init

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
/**
  * initialise a RC4 cipher.
  *
  * @param forEncryption whether or not we are for encryption.
  * @param params the parameters required to set up the cipher.
  * @exception IllegalArgumentException if the params argument is
  * inappropriate.
  */
 public void init(
     boolean             forEncryption, 
     CipherParameters     params
)
 {
     if (params instanceof KeyParameter)
     {
         /* 
          * RC4 encryption and decryption is completely
          * symmetrical, so the 'forEncryption' is 
          * irrelevant.
          */
         workingKey = ((KeyParameter)params).getKey();
         setKey(workingKey);

         return;
     }

     throw new IllegalArgumentException("invalid parameter passed to RC4 init - " + params.getClass().getName());
 }
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:29,代碼來源:RC4Engine.java

示例9: init

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
/**
 * initialise a CAST cipher.
 *
 * @param encrypting whether or not we are for encryption.
 * @param params the parameters required to set up the cipher.
 * @exception IllegalArgumentException if the params argument is
 * inappropriate.
 */
public void init(
    boolean             encrypting,
    CipherParameters    params)
{
    if (params instanceof KeyParameter)
    {
        _encrypting = encrypting;
        _workingKey = ((KeyParameter)params).getKey();

        setKey(_workingKey);

        return;
    }

    throw new IllegalArgumentException("Invalid parameter passed to "+getAlgorithmName()+" init - " + params.getClass().getName());
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:25,代碼來源:CAST5Engine.java

示例10: init

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
/**
 * initialise
 *
 * @param forEncryption whether or not we are for encryption.
 * @param params the parameters required to set up the cipher.
 * @exception IllegalArgumentException if the params argument is
 * inappropriate.
 */
public void init(
    boolean             forEncryption,
    CipherParameters    params)
{
    if (!(params instanceof KeyParameter))
    {
        throw new IllegalArgumentException("invalid parameter passed to TEA init - " + params.getClass().getName());
    }

    _forEncryption = forEncryption;
    _initialised = true;

    KeyParameter       p = (KeyParameter)params;

    setKey(p.getKey());
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:25,代碼來源:XTEAEngine.java

示例11: init

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
/**
 * initialise a RC2 cipher.
 *
 * @param encrypting whether or not we are for encryption.
 * @param params the parameters required to set up the cipher.
 * @exception IllegalArgumentException if the params argument is
 * inappropriate.
 */
public void init(
    boolean           encrypting,
    CipherParameters  params)
{
    this.encrypting = encrypting;

    if (params instanceof RC2Parameters)
    {
        RC2Parameters   param = (RC2Parameters)params;

        workingKey = generateWorkingKey(param.getKey(),
                                        param.getEffectiveKeyBits());
    }
    else if (params instanceof KeyParameter)
    {
        byte[]    key = ((KeyParameter)params).getKey();

        workingKey = generateWorkingKey(key, key.length * 8);
    }
    else
    {
        throw new IllegalArgumentException("invalid parameter passed to RC2 init - " + params.getClass().getName());
    }

}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:34,代碼來源:RC2Engine.java

示例12: init

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
/**
 * initialise a DES cipher.
 *
 * @param encrypting whether or not we are for encryption.
 * @param params the parameters required to set up the cipher.
 * @exception IllegalArgumentException if the params argument is
 * inappropriate.
 */
public void init(
    boolean           encrypting,
    CipherParameters  params)
{
    if (params instanceof KeyParameter)
    {
        if (((KeyParameter)params).getKey().length > 8)
        {
            throw new IllegalArgumentException("DES key too long - should be 8 bytes");
        }
        
        workingKey = generateWorkingKey(encrypting,
                              ((KeyParameter)params).getKey());

        return;
    }

    throw new IllegalArgumentException("invalid parameter passed to DES init - " + params.getClass().getName());
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:28,代碼來源:DESEngine.java

示例13: seal

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
/**
 * Encrypt a plaintext using the given key and nonce.
 *
 * @param nonce a 24-byte nonce (cf. {@link #nonce(ByteString)}, {@link #nonce()})
 * @param plaintext an arbitrary message
 * @return the ciphertext
 */
public ByteString seal(@Nonnull ByteString nonce, @Nonnull ByteString plaintext) {
  // initialize XSalsa20
  final XSalsa20Engine xsalsa20 = new XSalsa20Engine();
  xsalsa20.init(true, new ParametersWithIV(new KeyParameter(key), nonce.toByteArray()));

  // generate Poly1305 subkey
  final byte[] sk = new byte[32];
  xsalsa20.processBytes(sk, 0, 32, sk, 0);

  // encrypt plaintext
  final byte[] out = new byte[plaintext.size() + 16];
  xsalsa20.processBytes(plaintext.toByteArray(), 0, plaintext.size(), out, 16);

  // hash ciphertext and prepend mac to ciphertext
  final Poly1305 poly1305 = new Poly1305();
  poly1305.init(new KeyParameter(sk));
  poly1305.update(out, 16, plaintext.size());
  poly1305.doFinal(out, 0);
  return ByteString.of(out);
}
 
開發者ID:codahale,項目名稱:xsalsa20poly1305,代碼行數:28,代碼來源:SecretBox.java

示例14: init

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
/**
 * initialise
 *
 * @param forEncryption whether or not we are for encryption.
 * @param params the parameters required to set up the cipher.
 * @exception IllegalArgumentException if the params argument is
 * inappropriate.
 */
public void init(
                 boolean             forEncryption,
                 CipherParameters    params)
{
    if (!(params instanceof KeyParameter))
    {
        throw new IllegalArgumentException("invalid parameter passed to Noekeon init - " + params.getClass().getName());
    }
    
    _forEncryption = forEncryption;
    _initialised = true;
    
    KeyParameter       p = (KeyParameter)params;
    
    setKey(p.getKey());
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:25,代碼來源:NoekeonEngine.java

示例15: init

import org.bouncycastle.crypto.params.KeyParameter; //導入依賴的package包/類
public void init(
    boolean             forWrapping,
    CipherParameters    param)
{
    this.forWrapping = forWrapping;

    if (param instanceof ParametersWithRandom)
    {
        param = ((ParametersWithRandom) param).getParameters();
    }

    if (param instanceof KeyParameter)
    {
        this.param = (KeyParameter)param;
    }
    else if (param instanceof ParametersWithIV)
    {
        this.iv = ((ParametersWithIV)param).getIV();
        this.param = (KeyParameter)((ParametersWithIV) param).getParameters();
        if (this.iv.length != 8)
        {
           throw new IllegalArgumentException("IV not equal to 8");
        }
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:26,代碼來源:RFC3394WrapEngine.java


注:本文中的org.bouncycastle.crypto.params.KeyParameter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。