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


Java AEADParameters类代码示例

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


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

示例1: CipherWriteStreamValidation

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
public CipherWriteStreamValidation(byte[] secretBytes, byte[] salt) {
    this.salt = salt.clone();
    secretBytes = secretBytes.clone();
    if (secretBytes.length != KEY_SIZE_BYTES) {
        secretBytes = Hashing.sha256().hashBytes(secretBytes).asBytes();
    }
    try {
        KeyParameter key = new KeyParameter(secretBytes);
        AEADParameters params = new AEADParameters(key, MAC_SIZE_BITS, this.salt);

        this.encryptor = new GCMBlockCipher(new AESFastEngine());
        this.encryptor.init(true, params);

        this.decryptor = new GCMBlockCipher(new AESFastEngine());
        this.decryptor.init(false, params);

    } catch (Exception e) {
        throw new RuntimeException("could not create cipher for AES256", e);
    } finally {
        Arrays.fill(secretBytes, (byte) 0);
    }
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:23,代码来源:CipherWriteStreamValidation.java

示例2: init

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

示例3: runTestCase

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
private void runTestCase(String testName, String[] testVector, int macLengthBits, byte[] K)
    throws InvalidCipherTextException
{
    int pos = 0;
    byte[] N = Hex.decode(testVector[pos++]);
    byte[] A = Hex.decode(testVector[pos++]);
    byte[] P = Hex.decode(testVector[pos++]);
    byte[] C = Hex.decode(testVector[pos++]);

    int macLengthBytes = macLengthBits / 8;

    KeyParameter keyParameter = new KeyParameter(K);
    AEADParameters parameters = new AEADParameters(keyParameter, macLengthBits, N, A);

    AEADBlockCipher encCipher = initOCBCipher(true, parameters);
    AEADBlockCipher decCipher = initOCBCipher(false, parameters);

    checkTestCase(encCipher, decCipher, testName, macLengthBytes, P, C);
    checkTestCase(encCipher, decCipher, testName + " (reused)", macLengthBytes, P, C);

    // Key reuse
    AEADParameters keyReuseParams = AEADTestUtil.reuseKey(parameters);
    encCipher.init(true, keyReuseParams);
    decCipher.init(false, keyReuseParams);
    checkTestCase(encCipher, decCipher, testName + " (key reuse)", macLengthBytes, P, C);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:27,代码来源:OCBTest.java

示例4: doEax

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
private void doEax(byte[] key, byte[] iv, byte[] pt, byte[] aad, int tagLength, byte[] expected)
    throws InvalidCipherTextException
{
    EAXBlockCipher c = new EAXBlockCipher(new SerpentEngine());

    c.init(true, new AEADParameters(new KeyParameter(key), tagLength, iv, aad));

    byte[] out = new byte[expected.length];

    int len = c.processBytes(pt, 0, pt.length, out, 0);

    c.doFinal(out, len);

    if (!Arrays.areEqual(expected, out))
    {
        fail("EAX test failed");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:19,代码来源:SerpentTest.java

示例5: runTestCase

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
private void runTestCase(
    GCMMultiplier   encM,
    GCMMultiplier   decM,
    String          testName,
    byte[]          K,
    byte[]          IV,
    byte[]          A,
    byte[]          SA,
    byte[]          P,
    byte[]          C,
    byte[]          T)
    throws InvalidCipherTextException
{
    AEADParameters parameters = new AEADParameters(new KeyParameter(K), T.length * 8, IV, A);
    GCMBlockCipher encCipher = initCipher(encM, true, parameters);
    GCMBlockCipher decCipher = initCipher(decM, false, parameters);
    checkTestCase(encCipher, decCipher, testName, SA, P, C, T);
    checkTestCase(encCipher, decCipher, testName + " (reused)", SA, P, C, T);

    // Key reuse
    AEADParameters keyReuseParams = AEADTestUtil.reuseKey(parameters);
    encCipher.init(true, keyReuseParams);
    decCipher.init(false, keyReuseParams);
    checkTestCase(encCipher, decCipher, testName + " (key reuse)", SA, P, C, T);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:26,代码来源:GCMTest.java

示例6: SAES256v01

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
public SAES256v01(byte[] secretBytes, byte[] salt) {
    this.salt = salt.clone();
    secretBytes = secretBytes.clone();
    if (secretBytes.length != KEY_SIZE_BYTES) {
        secretBytes = Hashing.sha256().hashBytes(secretBytes).asBytes();
    }
    try {
        KeyParameter key = new KeyParameter(secretBytes);
        AEADParameters params = new AEADParameters(key, MAC_SIZE_BITS, this.salt);

        this.encryptor = new GCMBlockCipher(new AESFastEngine());
        this.encryptor.init(true, params);

        this.decryptor = new GCMBlockCipher(new AESFastEngine());
        this.decryptor.init(false, params);

    } catch (Exception e) {
        throw new RuntimeException("could not create cipher for AES256", e);
    } finally {
        Arrays.fill(secretBytes, (byte) 0);
    }
}
 
开发者ID:pitchpoint-solutions,项目名称:sfs,代码行数:23,代码来源:SAES256v01.java

示例7: EAXEncryptStream

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
public EAXEncryptStream(byte[] key, byte[] nonce, byte[] associatedData, OutputStream os)
{
	if(key.length != KEY_LENGTH_BYTES)
	{
		throw new IllegalArgumentException("key must be " + KEY_LENGTH_BYTES*8 + " bits");
	}
	
	this.cipher = new EAXBlockCipher(new AESEngine());
	this.os = os;
	
	keyParameter = new KeyParameter(key);
	AEADParameters par = new AEADParameters(keyParameter, EAXDecryptStream.MAC_LEN_BITS, nonce, associatedData);

	cipher.init(true, par);
	
	out = new byte[BUFFER_SIZE];
}
 
开发者ID:andy-goryachev,项目名称:PasswordSafe,代码行数:18,代码来源:EAXEncryptStream.java

示例8: EAXDecryptStream

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
public EAXDecryptStream(byte[] key, byte[] nonce, byte[] associatedData, InputStream in)
{
	if(key.length != KEY_LENGTH_BYTES)
	{
		throw new IllegalArgumentException("key must be " + KEY_LENGTH_BYTES*8 + " bits");
	}
	
	this.in = in;
	this.cipher = new EAXBlockCipher(new AESEngine());
	
	keyParameter = new KeyParameter(key);
	AEADParameters par = new AEADParameters(keyParameter, MAC_LEN_BITS, nonce, associatedData);

	cipher.init(false, par);

	out = new byte[BUFFER_SIZE];
	buf = new byte[BUFFER_SIZE];
}
 
开发者ID:andy-goryachev,项目名称:PasswordSafe,代码行数:19,代码来源:EAXDecryptStream.java

示例9: genKeyId

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
private AesKeyId genKeyId() {
    try {
        final GCMBlockCipher gcm = new GCMBlockCipher(new AESFastEngine());
        gcm.init(true, new AEADParameters(
            new KeyParameter(key), 128, KEYID_AD, KEYID_AD));
        final byte[] ciphertext = new byte[gcm.getOutputSize(ZERO_BYTES.length)];
        final int resp = gcm.processBytes(ZERO_BYTES, 0, ZERO_BYTES.length,
            ciphertext, 0);
        gcm.doFinal(ciphertext, resp);
        return new AesKeyId(ciphertext);
    } catch (final InvalidCipherTextException e) {
        // Should be impossible when we're encrypting!
        throw new RuntimeException(
            "Unexpected behaviour in crypto libraries", e);
    }
}
 
开发者ID:lshift,项目名称:bletchley,代码行数:17,代码来源:AesKey.java

示例10: decrypt

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
public SequenceItem decrypt(final ConverterCatalog r, final AesPacket packet)
    throws InvalidInputException {
    final GCMBlockCipher gcm = new GCMBlockCipher(new AESFastEngine());
    gcm.init(false, new AEADParameters(
        new KeyParameter(key), 128, packet.nonce, ZERO_BYTES));
    final byte[] newtext = new byte[
        gcm.getOutputSize(packet.ciphertext.length)];
    final int pp = gcm.processBytes(packet.ciphertext, 0,
        packet.ciphertext.length, newtext, 0);
    try {
        gcm.doFinal(newtext, pp);
    } catch (final InvalidCipherTextException e) {
        throw new CryptographyException(e);
    }
    return ConvertUtils.fromBytes(r, SequenceItem.class, newtext);
}
 
开发者ID:lshift,项目名称:bletchley,代码行数:17,代码来源:AesKey.java

示例11: decrypt

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
public static byte[] decrypt(byte[] key, byte[] data) {
    // TODO utilize GCMAES#decrypt method
    try {
        if (data.length < NONCE_LENGTH + TAG_LENGTH) {
            throw new IllegalArgumentException("data packet too short");
        }

        int cipherTextLength = data.length - NONCE_LENGTH - TAG_LENGTH;

        byte[] nonce = Arrays.copyOf(data, NONCE_LENGTH);

        GCMBlockCipher cipher = new GCMBlockCipher(new AESFastEngine());
        AEADParameters parameters = new AEADParameters(new KeyParameter(key), TAG_LENGTH * 8, nonce);
        cipher.init(false, parameters);

        byte[] out = new byte[cipher.getOutputSize(cipherTextLength + TAG_LENGTH)];

        int pos = cipher.processBytes(data, NONCE_LENGTH, data.length - NONCE_LENGTH, out, 0);
        pos += cipher.doFinal(out, pos);

        return Arrays.copyOf(out, pos);

    } catch (IllegalStateException | InvalidCipherTextException ex) {
        throw new IllegalArgumentException(ex);
    }
}
 
开发者ID:horrorho,项目名称:InflatableDonkey,代码行数:27,代码来源:GCMDataB.java

示例12: aesGcmEncrypt

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
public static byte[] aesGcmEncrypt(Transformation transformation, byte[] raw, byte[] secret, int atLength, byte[] iv, byte[] aad) throws Exception {
	BlockCipher blockCipher = new AESEngine();
	blockCipher.init(true, new KeyParameter(new SecretKeySpec(secret, "AES").getEncoded()));

	GCMBlockCipher aGCMBlockCipher = new GCMBlockCipher(blockCipher);
	aGCMBlockCipher.init(true, new AEADParameters(new KeyParameter(secret), atLength, iv, aad));

	int len = aGCMBlockCipher.getOutputSize(raw.length);
	byte[] out = new byte[len];
	int outOff = aGCMBlockCipher.processBytes(raw, 0, raw.length, out, 0);
	aGCMBlockCipher.doFinal(out, outOff);

	return out;
}
 
开发者ID:SKplanet,项目名称:syruppay-java,代码行数:15,代码来源:CryptoUtils.java

示例13: runTestCase

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
private void runTestCase(
    GCMMultiplier   encM,
    GCMMultiplier   decM,
    String          testName,
    byte[]          K,
    byte[]          IV,
    byte[]          A,
    byte[]          SA,
    byte[]          P,
    byte[]          C,
    byte[]          T)
    throws InvalidCipherTextException
{
    AEADParameters parameters = new AEADParameters(new KeyParameter(K), T.length * 8, IV, A);
    GCMBlockCipher encCipher = initCipher(encM, true, parameters);
    GCMBlockCipher decCipher = initCipher(decM, false, parameters);
    checkTestCase(encCipher, decCipher, testName, SA, P, C, T);
    checkTestCase(encCipher, decCipher, testName + " (reused)", SA, P, C, T);

    // Key reuse
    AEADParameters keyReuseParams = new AEADParameters(null, parameters.getMacSize(), parameters.getNonce(), parameters.getAssociatedText());
    encCipher.init(true, keyReuseParams);
    decCipher.init(false, keyReuseParams);
    checkTestCase(encCipher, decCipher, testName + " (key reuse)", SA, P, C, T);
    checkTestCase(encCipher, decCipher, testName + " (key reuse)", SA, P, C, T);
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:27,代码来源:GCMTest.java

示例14: encrypt

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
/**
 * Given the IV, encrypt the provided data
 *
 * @param IV      initialization vector
 * @param message data to be encrypted
 * @return byte array with the cipher text
 * @throws RuntimeException
 */
public byte[] encrypt(final byte[] IV, final byte[] message) throws RuntimeException {

    AEADParameters aeadParams = new AEADParameters(
            new KeyParameter(key), TAG_LENGTH,
            IV,
            authData);

    cipher.init(true, aeadParams);
    byte[] cipherText = newBuffer(cipher.getOutputSize(message.length));
    int outputOffset = cipher.processBytes(message, 0, message.length, cipherText, 0);

    try {
        cipher.doFinal(cipherText, outputOffset);
    } catch (InvalidCipherTextException e) {
        throw new RuntimeException("Error: ", e);
    }

    return cipherText;
}
 
开发者ID:aerogear,项目名称:aerogear-crypto-java,代码行数:28,代码来源:CryptoBox.java

示例15: decrypt

import org.bouncycastle.crypto.params.AEADParameters; //导入依赖的package包/类
/**
 * Given the IV, decrypt the provided data
 *
 * @param IV         initialization vector
 * @param cipherText data to be decrypted
 * @return byte array with the plain text
 * @throws RuntimeException
 */
public byte[] decrypt(byte[] IV, byte[] cipherText) throws RuntimeException {

    AEADParameters aeadParams = new AEADParameters(
            new KeyParameter(key), TAG_LENGTH,
            IV,
            authData);

    cipher.init(false, aeadParams);
    byte[] buffer = newByteArray(cipherText);
    byte[] plainText = newBuffer(cipher.getOutputSize(cipherText.length));
    int outputOffset = cipher.processBytes(buffer, 0, buffer.length, plainText, 0);

    try {
        cipher.doFinal(plainText, outputOffset);
    } catch (InvalidCipherTextException e) {
        throw new RuntimeException("Error: ", e);
    }

    return plainText;
}
 
开发者ID:aerogear,项目名称:aerogear-crypto-java,代码行数:29,代码来源:CryptoBox.java


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