本文整理匯總了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++;
}
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}