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