javax.crypto.spec.GCMParameterSpec#getTLen()源码实例Demo

下面列出了javax.crypto.spec.GCMParameterSpec#getTLen() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk9   文件: GCMParameterSpecTest.java
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;
}
 
源代码2 项目: dragonwell8_jdk   文件: GCMParameterSpecTest.java
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;
}
 
源代码3 项目: dragonwell8_jdk   文件: GCMParameterSpecTest.java
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++;
    }
}
 
源代码4 项目: hottub   文件: GCMParameterSpecTest.java
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++;
    }
}
 
源代码5 项目: TencentKona-8   文件: GCMParameterSpecTest.java
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;
}
 
源代码6 项目: jdk8u_jdk   文件: GCMParameterSpecTest.java
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++;
    }
}
 
源代码7 项目: jdk8u-jdk   文件: GCMParameterSpecTest.java
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++;
    }
}
 
源代码8 项目: openjdk-jdk8u   文件: GCMParameterSpecTest.java
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++;
    }
}
 
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;
}
 
private static void newGCMParameterSpecPass(
        int tLen, byte[] src) {
    try {
        GCMParameterSpec gcmps = new GCMParameterSpec(tLen, src);
        if (gcmps.getTLen() != tLen) {
            throw new Exception("tLen's not equal");
        }
        if (!Arrays.equals(gcmps.getIV(), src)) {
            throw new Exception("IV's not equal");
        }
    } catch (Exception e) {
        e.printStackTrace();
        failed++;
    }
}
 
源代码11 项目: openjdk-jdk9   文件: GCMParameterSpecTest.java
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;
}
 
源代码12 项目: TencentKona-8   文件: GCMParameters.java
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();
}
 
源代码13 项目: openjdk-jdk9   文件: GCMParameterSpecTest.java
private static void newGCMParameterSpecPass(
        int tLen, byte[] src) {
    try {
        GCMParameterSpec gcmps = new GCMParameterSpec(tLen, src);
        if (gcmps.getTLen() != tLen) {
            throw new Exception("tLen's not equal");
        }
        if (!Arrays.equals(gcmps.getIV(), src)) {
            throw new Exception("IV's not equal");
        }
    } catch (Exception e) {
        e.printStackTrace();
        failed++;
    }
}
 
源代码14 项目: hottub   文件: GCMParameterSpecTest.java
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;
}
 
源代码15 项目: jdk8u60   文件: GCMParameters.java
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();
}
 
源代码16 项目: jdk8u60   文件: GCMParameterSpecTest.java
private static void newGCMParameterSpecPass(
        int tLen, byte[] src) {
    try {
        GCMParameterSpec gcmps = new GCMParameterSpec(tLen, src);
        if (gcmps.getTLen() != tLen) {
            throw new Exception("tLen's not equal");
        }
        if (!Arrays.equals(gcmps.getIV(), src)) {
            throw new Exception("IV's not equal");
        }
    } catch (Exception e) {
        e.printStackTrace();
        failed++;
    }
}
 
源代码17 项目: openjdk-jdk8u   文件: GCMParameterSpecTest.java
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;
}
 
源代码18 项目: openjdk-8   文件: GCMParameters.java
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();
}
 
源代码19 项目: openjdk-jdk8u   文件: GCMParameterSpecTest.java
private static void newGCMParameterSpecPass(
        int tLen, byte[] src) {
    try {
        GCMParameterSpec gcmps = new GCMParameterSpec(tLen, src);
        if (gcmps.getTLen() != tLen) {
            throw new Exception("tLen's not equal");
        }
        if (!Arrays.equals(gcmps.getIV(), src)) {
            throw new Exception("IV's not equal");
        }
    } catch (Exception e) {
        e.printStackTrace();
        failed++;
    }
}
 
源代码20 项目: jdk8u-jdk   文件: GCMParameterSpecTest.java
private static void newGCMParameterSpecPass(
        int tLen, byte[] src) {
    try {
        GCMParameterSpec gcmps = new GCMParameterSpec(tLen, src);
        if (gcmps.getTLen() != tLen) {
            throw new Exception("tLen's not equal");
        }
        if (!Arrays.equals(gcmps.getIV(), src)) {
            throw new Exception("IV's not equal");
        }
    } catch (Exception e) {
        e.printStackTrace();
        failed++;
    }
}
 
 同类方法