本文整理了Java中javax.crypto.Cipher.getOutputSize()
方法的一些代码示例,展示了Cipher.getOutputSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cipher.getOutputSize()
方法的具体详情如下:
包路径:javax.crypto.Cipher
类名称:Cipher
方法名:getOutputSize
[英]Returns the length in bytes an output buffer needs to be when this cipher is updated with inputLen bytes.
[中]返回使用inputLen字节更新此密码时输出缓冲区需要的字节长度。
代码示例来源:origin: aws/aws-sdk-java
int getOutputSize(int inputLen) {
return cipher.getOutputSize(inputLen);
}
}
代码示例来源:origin: apache/usergrid
public static ByteBuffer decrypt( ByteBuffer encrypted ) {
if ( encrypted == null || !encrypted.hasRemaining() ) {
return encrypted;
}
try {
SecretKeySpec sKeySpec = new SecretKeySpec( getRawKey( encryptionSeed ), "AES" );
Cipher cipher = Cipher.getInstance( "AES" );
cipher.init( Cipher.DECRYPT_MODE, sKeySpec );
ByteBuffer decrypted = ByteBuffer.allocate( cipher.getOutputSize( encrypted.remaining() ) );
cipher.doFinal( encrypted, decrypted );
decrypted.rewind();
return decrypted;
}
catch ( Exception e ) {
throw new IllegalStateException( e );
}
}
代码示例来源:origin: apache/usergrid
public static ByteBuffer encrypt( ByteBuffer clear ) {
if ( clear == null || !clear.hasRemaining() ) {
return clear;
}
try {
SecretKeySpec sKeySpec = new SecretKeySpec( getRawKey( encryptionSeed ), "AES" );
Cipher cipher = Cipher.getInstance( "AES" );
cipher.init( Cipher.ENCRYPT_MODE, sKeySpec );
ByteBuffer encrypted = ByteBuffer.allocate( cipher.getOutputSize( clear.remaining() ) );
cipher.doFinal( clear, encrypted );
encrypted.rewind();
return encrypted;
}
catch ( Exception e ) {
throw new IllegalStateException( e );
}
}
代码示例来源:origin: apache/pulsar
private ByteBuf decryptData(SecretKey dataKeySecret, MessageMetadata msgMetadata, ByteBuf payload) {
// unpack iv and encrypted data
ByteString ivString = msgMetadata.getEncryptionParam();
ivString.copyTo(iv, 0);
GCMParameterSpec gcmParams = new GCMParameterSpec(tagLen, iv);
ByteBuf targetBuf = null;
try {
cipher.init(Cipher.DECRYPT_MODE, dataKeySecret, gcmParams);
ByteBuffer sourceNioBuf = payload.nioBuffer(payload.readerIndex(), payload.readableBytes());
int maxLength = cipher.getOutputSize(payload.readableBytes());
targetBuf = PooledByteBufAllocator.DEFAULT.buffer(maxLength, maxLength);
ByteBuffer targetNioBuf = targetBuf.nioBuffer(0, maxLength);
int decryptedSize = cipher.doFinal(sourceNioBuf, targetNioBuf);
targetBuf.writerIndex(decryptedSize);
} catch (InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException
| BadPaddingException | ShortBufferException e) {
log.error("{} Failed to decrypt message {}", logCtx, e.getMessage());
if (targetBuf != null) {
targetBuf.release();
targetBuf = null;
}
}
return targetBuf;
}
代码示例来源:origin: robovm/robovm
int outputSize = cipher.getOutputSize(inputBuffer.length);
if ((outputBuffer == null) || (outputBuffer.length < outputSize)) {
this.outputBuffer = new byte[outputSize];
代码示例来源:origin: apache/pulsar
int maxLength = cipher.getOutputSize(payload.readableBytes());
targetBuf = PooledByteBufAllocator.DEFAULT.buffer(maxLength, maxLength);
ByteBuffer targetNioBuf = targetBuf.nioBuffer(0, maxLength);
代码示例来源:origin: aws-amplify/aws-sdk-android
int getOutputSize(int inputLen) {
return cipher.getOutputSize(inputLen);
}
}
代码示例来源:origin: SpigotMC/BungeeCord
@Override
public void cipher(ByteBuf in, ByteBuf out) throws ShortBufferException
{
int readableBytes = in.readableBytes();
byte[] heapIn = bufToByte( in );
byte[] heapOut = heapOutLocal.get();
int outputSize = cipher.getOutputSize( readableBytes );
if ( heapOut.length < outputSize )
{
heapOut = new byte[ outputSize ];
heapOutLocal.set( heapOut );
}
out.writeBytes( heapOut, 0, cipher.update( heapIn, 0, readableBytes, heapOut ) );
}
代码示例来源:origin: SpigotMC/BungeeCord
@Override
public ByteBuf cipher(ChannelHandlerContext ctx, ByteBuf in) throws ShortBufferException
{
int readableBytes = in.readableBytes();
byte[] heapIn = bufToByte( in );
ByteBuf heapOut = ctx.alloc().heapBuffer( cipher.getOutputSize( readableBytes ) );
heapOut.writerIndex( cipher.update( heapIn, 0, readableBytes, heapOut.array(), heapOut.arrayOffset() ) );
return heapOut;
}
代码示例来源:origin: stackoverflow.com
byte[] cipherText = new byte[cipher.getOutputSize(input.length)];
int ctLength = cipher.update(input, 0, input.length, cipherText, 0);
ctLength += cipher.doFinal(cipherText, ctLength);
byte[] plainText = new byte[cipher.getOutputSize(ctLength)];
int ptLength = cipher.update(cipherText, 0, ctLength, plainText, 0);
ptLength += cipher.doFinal(plainText, ptLength);
代码示例来源:origin: ibinti/bugvm
/**
* Returns the minimal possible size of the
* Generic[Stream|Block]Cipher structure under this
* connection state.
*/
protected int getMinFragmentSize() {
// block ciphers return value with padding included
return encCipher.getOutputSize(1+hash_size); // 1 byte for data
}
代码示例来源:origin: com.bugvm/bugvm-rt
/**
* Returns the minimal upper bound of the content size enclosed
* into the Generic[Stream|Block]Cipher structure of specified size.
* For stream ciphers the returned value will be exact value.
*/
protected int getContentSize(int generic_cipher_size) {
//it does not take the padding of block ciphered structures
//into account (so returned value can be greater than actual)
return decCipher.getOutputSize(generic_cipher_size)-hash_size;
}
代码示例来源:origin: com.bugvm/bugvm-rt
/**
* Returns the minimal possible size of the
* Generic[Stream|Block]Cipher structure under this
* connection state.
*/
protected int getMinFragmentSize() {
// block ciphers return value with padding included
return encCipher.getOutputSize(1+hash_size); // 1 byte for data
}
代码示例来源:origin: com.bugvm/bugvm-rt
/**
* Returns the size of the Generic[Stream|Block]Cipher structure
* corresponding to the content data of specified size.
*/
protected int getFragmentSize(int content_size) {
return encCipher.getOutputSize(content_size+hash_size);
}
代码示例来源:origin: ibinti/bugvm
/**
* Returns the size of the Generic[Stream|Block]Cipher structure
* corresponding to the content data of specified size.
*/
protected int getFragmentSize(int content_size) {
return encCipher.getOutputSize(content_size+hash_size);
}
代码示例来源:origin: ibinti/bugvm
/**
* Returns the minimal upper bound of the content size enclosed
* into the Generic[Stream|Block]Cipher structure of specified size.
* For stream ciphers the returned value will be exact value.
*/
protected int getContentSize(int generic_cipher_size) {
//it does not take the padding of block ciphered structures
//into account (so returned value can be greater than actual)
return decCipher.getOutputSize(generic_cipher_size)-hash_size;
}
代码示例来源:origin: i2p/i2p.i2p-bote
protected byte[] decryptAes(byte[] data, byte[] key, byte[] iv) throws GeneralSecurityException {
SecretKeySpec keySpec = new SecretKeySpec(key, "AES");
IvParameterSpec ivps = new IvParameterSpec(iv, 0, 16);
aesCipher.init(Cipher.DECRYPT_MODE, keySpec, ivps, appContext.random());
byte[] decryptedData = new byte[aesCipher.getOutputSize(data.length)];
int decLen = aesCipher.doFinal(data, 0, data.length, decryptedData, 0);
byte[] ret = new byte[decLen];
System.arraycopy(decryptedData, 0, ret, 0, decLen);
return ret;
}
}
代码示例来源:origin: EngineHub/CommandHelper
public char[] getDecryptedCharArray() {
try {
byte[] decrypted = new byte[decrypter.getOutputSize(encLength)];
int decLen = decrypter.update(encrypted, 0, encLength, decrypted, 0);
decrypter.doFinal(decrypted, decLen);
decrypted = ArrayUtils.slice(decrypted, 0, actualLength - 1);
return ArrayUtils.bytesToChar(decrypted);
} catch (ShortBufferException | IllegalBlockSizeException | BadPaddingException ex) {
throw new RuntimeException(ex);
}
}
代码示例来源:origin: voxelwind/voxelwind
@Override
public ByteBuf cipher(ChannelHandlerContext ctx, ByteBuf in) throws ShortBufferException
{
int readableBytes = in.readableBytes();
byte[] heapIn = bufToByte( in );
ByteBuf heapOut = ctx.alloc().heapBuffer( cipher.getOutputSize( readableBytes ) );
heapOut.writerIndex( cipher.update( heapIn, 0, readableBytes, heapOut.array(), heapOut.arrayOffset() ) );
return heapOut;
}
代码示例来源:origin: VelocityPowered/Velocity
@Override
public ByteBuf process(ChannelHandlerContext ctx, ByteBuf source) throws ShortBufferException {
ensureNotDisposed();
int inBytes = source.readableBytes();
ByteBuf asHeapBuf = asHeapBuf(source);
ByteBuf out = ctx.alloc().heapBuffer(cipher.getOutputSize(inBytes));
out.writerIndex(cipher.update(asHeapBuf.array(), asHeapBuf.arrayOffset(), inBytes, out.array(),
out.arrayOffset()));
return out;
}
内容来源于网络,如有侵权,请联系作者删除!