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


Java ParametersWithIV类代码示例

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


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

示例1: decrypt

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的package包/类
@Override
    public String decrypt(byte[] encrypted) {
//        Cipher cipher = null;
        String plain;
        try {
//            Security.addProvider(new BouncyCastlePQCProvider());
//            cipher = Cipher.getInstance("AES/CBC/PKCS5Padding", new BouncyCastlePQCProvider());
//            cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(encryptionKey, "AES"), new IvParameterSpec(iv));
//            plain = new String(cipher.doFinal(encrypted), "UTF-8");
            KeyParameter keyParam = new KeyParameter(encryptionKey);
            CipherParameters params = new ParametersWithIV(keyParam, iv);
            BlockCipherPadding padding = new PKCS7Padding();
            BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(
                    new CBCBlockCipher(new AESEngine()), padding);
            cipher.reset();
            cipher.init(false, params);
            byte[] buffer = new byte[cipher.getOutputSize(encrypted.length)];
            int len = cipher.processBytes(encrypted, 0, encrypted.length, buffer, 0);
            len += cipher.doFinal(buffer, len);
            byte[] out = Arrays.copyOfRange(buffer, 0, len);
            plain = new String(out, "UTF-8");
        } catch (Exception e) {
            throw new RuntimeException("decrypt error in SimpleAesManaged", e);
        }
        return plain;
    }
 
开发者ID:timerickson,项目名称:lastpass-java,代码行数:27,代码来源:SimpleAesManaged.java

示例2: generateDerivedParameters

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的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

示例3: getSalsa20

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的package包/类
private static StreamCipher getSalsa20(byte[] key) {
	// Build stream cipher key
	MessageDigest md;
	try {
		md = MessageDigest.getInstance("SHA-256");
	} catch (NoSuchAlgorithmException e) {
		e.printStackTrace();
		throw new RuntimeException("SHA 256 not supported");
	}
	byte[] key32 = md.digest(key);
	
	KeyParameter keyParam = new KeyParameter(key32);
	ParametersWithIV ivParam = new ParametersWithIV(keyParam, SALSA_IV);
	
	StreamCipher cipher = new Salsa20Engine();
	cipher.init(true, ivParam);
	
	return cipher;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:20,代码来源:PwStreamCipherFactory.java

示例4: createCipherParameters

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的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

示例5: init

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的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

示例6: init

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的package包/类
/**
 * Initialises the GMAC - requires a {@link ParametersWithIV} providing a {@link KeyParameter}
 * and a nonce.
 */
public void init(final CipherParameters params) throws IllegalArgumentException
{
    if (params instanceof ParametersWithIV)
    {
        final ParametersWithIV param = (ParametersWithIV)params;

        final byte[] iv = param.getIV();
        final KeyParameter keyParam = (KeyParameter)param.getParameters();

        // GCM is always operated in encrypt mode to calculate MAC
        cipher.init(true, new AEADParameters(keyParam, macSizeBits, iv));
    }
    else
    {
        throw new IllegalArgumentException("GMAC requires ParametersWithIV");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:22,代码来源:GMac.java

示例7: init

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的package包/类
public void init(
    boolean             forEncryption, //ignored by this CTR mode
    CipherParameters    params)
    throws IllegalArgumentException
{
    if (params instanceof ParametersWithIV)
    {
      ParametersWithIV ivParam = (ParametersWithIV)params;
      byte[]           iv      = ivParam.getIV();
      System.arraycopy(iv, 0, IV, 0, IV.length);

      reset();

      // if null it's an IV changed only.
      if (ivParam.getParameters() != null)
      {
        cipher.init(true, ivParam.getParameters());
      }
    }
    else
    {
        throw new IllegalArgumentException("SIC mode requires ParametersWithIV");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:SICBlockCipher.java

示例8: extractSecretKey

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的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

示例9: aesEncrypt

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的package包/类
public static byte[] aesEncrypt(byte[] plaintext, byte[] myPrivateKey, byte[] theirPublicKey, byte[] nonce) {
    try {
        byte[] dhSharedSecret = new byte[32];
        Curve25519.curve(dhSharedSecret, myPrivateKey, theirPublicKey);
        for (int i = 0; i < 32; i++) {
            dhSharedSecret[i] ^= nonce[i];
        }
        byte[] key = sha256().digest(dhSharedSecret);
        byte[] iv = new byte[16];
        secureRandom.get().nextBytes(iv);
        PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(
                new AESEngine()));
        CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
        aes.init(true, ivAndKey);
        byte[] output = new byte[aes.getOutputSize(plaintext.length)];
        int ciphertextLength = aes.processBytes(plaintext, 0, plaintext.length, output, 0);
        ciphertextLength += aes.doFinal(output, ciphertextLength);
        byte[] result = new byte[iv.length + ciphertextLength];
        System.arraycopy(iv, 0, result, 0, iv.length);
        System.arraycopy(output, 0, result, iv.length, ciphertextLength);
        return result;
    } catch (InvalidCipherTextException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
开发者ID:muhatzg,项目名称:burstcoin,代码行数:26,代码来源:Crypto.java

示例10: seal

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的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

示例11: compareModes

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的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);
}
 
开发者ID:christian-schlichtherle,项目名称:truevfs,代码行数:24,代码来源:CtrBlockCipherTest.java

示例12: encryptOrDecrypt

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的package包/类
private byte[] encryptOrDecrypt(byte[] key, byte[] contents, boolean forEncryption) {

        // Credstash uses standard AES
        BlockCipher engine = new AESFastEngine();

        // Credstash uses CTR mode
        StreamBlockCipher cipher = new SICBlockCipher(engine);

        cipher.init(forEncryption, new ParametersWithIV(new KeyParameter(key), INITIALIZATION_VECTOR));

        byte[] resultBytes = new byte[contents.length];
        int contentsOffset = 0;
        int resultOffset = 0;
        cipher.processBytes(contents, contentsOffset, contents.length, resultBytes, resultOffset);
        return resultBytes;
    }
 
开发者ID:jessecoyle,项目名称:jcredstash,代码行数:17,代码来源:CredStashBouncyCastleCrypto.java

示例13: aesDecrypt

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的package包/类
public static byte[] aesDecrypt(byte[] ivCiphertext, byte[] myPrivateKey, byte theirPublicKey[]) {
    try {
        if (ivCiphertext.length < 16 || ivCiphertext.length % 16 != 0) {
            throw new InvalidCipherTextException("invalid ciphertext");
        }
        byte[] iv = Arrays.copyOfRange(ivCiphertext, 0, 16);
        byte[] ciphertext = Arrays.copyOfRange(ivCiphertext, 16, ivCiphertext.length);
        byte[] dhSharedSecret = new byte[32];
        Curve25519.curve(dhSharedSecret, myPrivateKey, theirPublicKey);
        byte[] key = sha256().digest(dhSharedSecret);
        PaddedBufferedBlockCipher aes = new PaddedBufferedBlockCipher(new CBCBlockCipher(
                new AESEngine()));
        CipherParameters ivAndKey = new ParametersWithIV(new KeyParameter(key), iv);
        aes.init(false, ivAndKey);
        byte[] output = new byte[aes.getOutputSize(ciphertext.length)];
        int plaintextLength = aes.processBytes(ciphertext, 0, ciphertext.length, output, 0);
        plaintextLength += aes.doFinal(output, plaintextLength);
        byte[] result = new byte[plaintextLength];
        System.arraycopy(output, 0, result, 0, result.length);
        return result;
    } catch (InvalidCipherTextException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
开发者ID:de-luxe,项目名称:burstcoin-faucet,代码行数:25,代码来源:Crypto.java

示例14: initRecordMAC

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的package包/类
protected KeyParameter initRecordMAC(ChaChaEngine cipher, boolean forEncryption, long seqNo)
{
    byte[] nonce = new byte[8];
    TlsUtils.writeUint64(seqNo, nonce, 0);

    cipher.init(forEncryption, new ParametersWithIV(null, nonce));

    byte[] firstBlock = new byte[64];
    cipher.processBytes(firstBlock, 0, firstBlock.length, firstBlock, 0);

    // NOTE: The BC implementation puts 'r' after 'k'
    System.arraycopy(firstBlock, 0, firstBlock, 32, 16);
    KeyParameter macKey = new KeyParameter(firstBlock, 16, 32);
    Poly1305KeyGenerator.clamp(macKey.getKey());
    return macKey;
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:17,代码来源:Chacha20Poly1305.java

示例15: init

import org.bouncycastle.crypto.params.ParametersWithIV; //导入依赖的package包/类
public void init(boolean forEncryption, CipherParameters params)
    throws IllegalArgumentException
{
    counter = 0;
    cfbEngine.init(forEncryption, params);

    this.forEncryption = forEncryption;

    if (params instanceof ParametersWithIV)
    {
        params = ((ParametersWithIV)params).getParameters();
    }

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

    if (params instanceof ParametersWithSBox)
    {
        params = ((ParametersWithSBox)params).getParameters();
    }

    key = (KeyParameter)params;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:26,代码来源:GCFBBlockCipher.java


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