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


Java GCMParameterSpec.getIV方法代碼示例

本文整理匯總了Java中javax.crypto.spec.GCMParameterSpec.getIV方法的典型用法代碼示例。如果您正苦於以下問題:Java GCMParameterSpec.getIV方法的具體用法?Java GCMParameterSpec.getIV怎麽用?Java GCMParameterSpec.getIV使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.crypto.spec.GCMParameterSpec的用法示例。


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

示例1: encryptTLS12

import javax.crypto.spec.GCMParameterSpec; //導入方法依賴的package包/類
private EncryptionResult encryptTLS12(EncryptionRequest request) {
    try {
        byte[] nonce = ArrayConverter.longToBytes(context.getWriteSequenceNumber(),
                RecordByteLength.SEQUENCE_NUMBER);
        byte[] iv = ArrayConverter.concatenate(
                getKeySet().getWriteIv(context.getConnection().getLocalConnectionEndType()), nonce);
        encryptIV = new GCMParameterSpec(GCM_TAG_LENGTH * 8, iv);
        LOGGER.debug("Encrypting GCM with the following IV: {}", ArrayConverter.bytesToHexString(encryptIV.getIV()));
        encryptCipher.init(Cipher.ENCRYPT_MODE, encryptKey, encryptIV);
        LOGGER.debug("Encrypting GCM with the following AAD: {}",
                ArrayConverter.bytesToHexString(additionalAuthenticatedData));
        encryptCipher.updateAAD(additionalAuthenticatedData);
        byte[] ciphertext = encryptCipher.doFinal(request.getPlainText());
        return new EncryptionResult(encryptIV.getIV(), ArrayConverter.concatenate(nonce, ciphertext), false);
    } catch (BadPaddingException | IllegalBlockSizeException | InvalidKeyException
            | InvalidAlgorithmParameterException ex) {
        throw new CryptoException(ex);
    }
}
 
開發者ID:RUB-NDS,項目名稱:TLS-Attacker,代碼行數:20,代碼來源:RecordAEADCipher.java

示例2: init

import javax.crypto.spec.GCMParameterSpec; //導入方法依賴的package包/類
@Override
public void init(int mode, byte[] key, AlgorithmParameterSpec params)
        throws InvalidAlgorithmParameterException {

    if (aadBuffer == null) {
        aadBuffer = new ByteArrayOutputStream();
    } else {
        aadBuffer.reset();
    }

    this.cipherMode = mode;
    byte[] iv;
    if (params instanceof GCMParameterSpec) {
        GCMParameterSpec gcmParam = (GCMParameterSpec) params;
        iv = gcmParam.getIV();
        this.tagBitLen = gcmParam.getTLen();
    } else {
        // other AlgorithmParameterSpec is not supported now.
        throw new InvalidAlgorithmParameterException("Illegal parameters");
    }

    if (this.cipherMode == OpenSsl.DECRYPT_MODE) {
        inBuffer = new ByteArrayOutputStream();
    }

    context = OpenSslNative.init(context, mode, algorithmMode, padding, key, iv);
}
 
開發者ID:apache,項目名稱:commons-crypto,代碼行數:28,代碼來源:OpenSslGaloisCounterMode.java

示例3: engineInit

import javax.crypto.spec.GCMParameterSpec; //導入方法依賴的package包/類
protected void engineInit(AlgorithmParameterSpec paramSpec)
    throws InvalidParameterSpecException {

    if (!(paramSpec instanceof GCMParameterSpec)) {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
    GCMParameterSpec gps = (GCMParameterSpec) paramSpec;
    // need to convert from bits to bytes for ASN.1 encoding
    this.tLen = gps.getTLen()/8;
    this.iv = gps.getIV();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:13,代碼來源:GCMParameters.java

示例4: fromGCMParameterSpec

import javax.crypto.spec.GCMParameterSpec; //導入方法依賴的package包/類
/**
 * Convert from platform's GCMParameterSpec to our internal version.
 */
static GCMParameters fromGCMParameterSpec(AlgorithmParameterSpec params) {
    if (params instanceof GCMParameterSpec) {
        GCMParameterSpec gcmParams = (GCMParameterSpec) params;
        return new GCMParameters(gcmParams.getTLen(), gcmParams.getIV());
    }
    return null;
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:11,代碼來源:Platform.java

示例5: fromGCMParameterSpec

import javax.crypto.spec.GCMParameterSpec; //導入方法依賴的package包/類
/**
 * Convert from platform's GCMParameterSpec to our internal version.
 */
@SuppressWarnings("unused")
static GCMParameters fromGCMParameterSpec(AlgorithmParameterSpec params) {
    if (params instanceof GCMParameterSpec) {
        GCMParameterSpec gcmParams = (GCMParameterSpec) params;
        return new GCMParameters(gcmParams.getTLen(), gcmParams.getIV());
    }
    return null;
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:12,代碼來源:Platform.java

示例6: specToBytes

import javax.crypto.spec.GCMParameterSpec; //導入方法依賴的package包/類
private static byte[] specToBytes(final GCMParameterSpec spec) {
    final byte[] nonce = spec.getIV();
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try (final DataOutputStream dos = new DataOutputStream(baos)) {
        dos.writeInt(spec.getTLen());
        dos.writeInt(nonce.length);
        dos.write(nonce);
        dos.close();
        baos.close();
    } catch (final IOException ex) {
        throw new AssertionError("Impossible exception", ex);
    }
    return baos.toByteArray();
}
 
開發者ID:awslabs,項目名稱:aws-encryption-sdk-java,代碼行數:15,代碼來源:JceMasterKey.java


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