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


Java GCMParameterSpec.getTLen方法代碼示例

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


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

示例1: newGCMParameterSpecPass

import javax.crypto.spec.GCMParameterSpec; //導入方法依賴的package包/類
private static void newGCMParameterSpecPass(
        int tLen, byte[] src, int offset, int len) {
    try {
        GCMParameterSpec gcmps =
            new GCMParameterSpec(tLen, src, offset, len);
        if (gcmps.getTLen() != tLen) {
            throw new Exception("tLen's not equal");
        }
        if (!Arrays.equals(gcmps.getIV(),
                Arrays.copyOfRange(src, offset, offset + len))) {
            System.out.println(offset + " " + len);
            System.out.println(Arrays.copyOfRange(src, offset, len)[0]);
            throw new Exception("IV's not equal");
        }
    } catch (Exception e) {
        e.printStackTrace();
        failed++;
    }
}
 
開發者ID:JetBrains,項目名稱:jdk8u_jdk,代碼行數:20,代碼來源:GCMParameterSpecTest.java

示例2: getCipherTextBySpec

import javax.crypto.spec.GCMParameterSpec; //導入方法依賴的package包/類
private byte[] getCipherTextBySpec(GCMParameterSpec spec) throws Exception {
    // init a cipher
    Cipher cipher = createCipher(Cipher.ENCRYPT_MODE, spec);
    cipher.updateAAD(AAD);
    byte[] cipherText = cipher.doFinal(data);

    // check IVs
    if (!Arrays.equals(cipher.getIV(), spec.getIV())) {
        System.out.println("IV in parameters is incorrect");
        return null;
    }
    if (spec.getTLen() != (cipherText.length - data.length) * 8) {
        System.out.println("Tag length is incorrect");
        return null;
    }
    return cipherText;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:GCMParameterSpecTest.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: doTest

import javax.crypto.spec.GCMParameterSpec; //導入方法依賴的package包/類
private boolean doTest() throws Exception {
    GCMParameterSpec spec1 = new GCMParameterSpec(tagLength, IV);
    GCMParameterSpec spec2 = new GCMParameterSpec(tagLength, IVO, offset,
            IVlength);
    byte[] cipherText1 = getCipherTextBySpec(spec1);
    if (cipherText1 == null) {
        return false;
    }
    byte[] cipherText2 = getCipherTextBySpec(spec2);
    if (cipherText2 == null) {
        return false;
    }
    if (!Arrays.equals(cipherText1, cipherText2)) {
        System.out.println("Cipher texts are different");
        return false;
    }
    if (spec1.getTLen() != spec2.getTLen()) {
        System.out.println("Tag lengths are not equal");
        return false;
    }
    byte[] recoveredText1 = recoverCipherText(cipherText1, spec2);
    if (recoveredText1 == null) {
        return false;
    }
    byte[] recoveredText2 = recoverCipherText(cipherText2, spec1);
    if (recoveredText2 == null) {
        return false;
    }
    if (!Arrays.equals(recoveredText1, recoveredText2)) {
        System.out.println("Recovered texts are different");
        return false;
    }
    if (!Arrays.equals(recoveredText1, data)) {
        System.out.println("Recovered and original texts are not equal");
        return false;
    }

    return true;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:40,代碼來源:GCMParameterSpecTest.java

示例5: 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

示例6: 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

示例7: 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


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