当前位置: 首页>>代码示例>>Java>>正文


Java ShortBufferException类代码示例

本文整理汇总了Java中javax.crypto.ShortBufferException的典型用法代码示例。如果您正苦于以下问题:Java ShortBufferException类的具体用法?Java ShortBufferException怎么用?Java ShortBufferException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ShortBufferException类属于javax.crypto包,在下文中一共展示了ShortBufferException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: engineUpdate

import javax.crypto.ShortBufferException; //导入依赖的package包/类
protected int engineUpdate(
    byte[]  input,
    int     inputOffset,
    int     inputLen,
    byte[]  output,
    int     outputOffset)
    throws ShortBufferException
{
    try
    {
        return cipher.processBytes(input, inputOffset, inputLen, output, outputOffset);
    }
    catch (DataLengthException e)
    {
        throw new ShortBufferException(e.getMessage());
    }
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:18,代码来源:JCEBlockCipher.java

示例2: engineDoFinal

import javax.crypto.ShortBufferException; //导入依赖的package包/类
@Override
protected byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
		throws IllegalBlockSizeException, BadPaddingException {
	int maxSize = engineGetOutputSize(inputLen);
	byte[] output = new byte[maxSize];
	
	int finalSize;
	
	try {
		finalSize = doFinal(input, inputOffset, inputLen, output, 0);
	} catch (ShortBufferException e) {
		// This shouldn't be possible rethrow as RuntimeException
		throw new RuntimeException("Short buffer exception shouldn't be possible from here.");
	}
	
	if ( maxSize == finalSize ) {
		return output;
	} else {
		// TODO: Special doFinal to avoid this copy
		byte[] exact = new byte[finalSize];
		System.arraycopy(output, 0, exact, 0, finalSize);
		return exact;
	}
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:25,代码来源:NativeAESCipherSpi.java

示例3: update

import javax.crypto.ShortBufferException; //导入依赖的package包/类
public int update(ByteBuffer input, ByteBuffer output)
    throws ShortBufferException {
    //checkState();
    Preconditions.checkArgument(input.isDirect() && output.isDirect(),
         "Direct buffers are required.");
    try {
      int outputPosition = output.position();
      if (mode == TRANSFORM_MODE)
        transform(input, output);
      else if (mode == ENCRYPT_MODE)
        encrypt(input, output);
      else
        decrypt(input, output);
      return output.position() - outputPosition;
    } catch (IOException e) {
      e.printStackTrace();
    }
    return 0;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:20,代码来源:BBS98BCCipher.java

示例4: doFinal

import javax.crypto.ShortBufferException; //导入依赖的package包/类
/**
 * Finish a multiple-part encryption or decryption operation (depending on
 * how this cipher was initialized).
 *
 * @param input  the input buffer
 * @param inOff  the offset where the input starts
 * @param inLen  the input length
 * @param output the buffer for the result
 * @param outOff the offset where the result is stored
 * @return the output length
 * @throws ShortBufferException if the output buffer is too small to hold the result.
 * @throws IllegalBlockSizeException if the plaintext or ciphertext size is too large.
 * @throws BadPaddingException if the ciphertext is invalid.
 */
public final int doFinal(byte[] input, int inOff, int inLen, byte[] output,
                         int outOff)
    throws ShortBufferException, IllegalBlockSizeException,
    BadPaddingException
{

    if (output.length < getOutputSize(inLen))
    {
        throw new ShortBufferException("Output buffer too short.");
    }

    byte[] out = doFinal(input, inOff, inLen);
    System.arraycopy(out, 0, output, outOff, out.length);
    return out.length;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:30,代码来源:AsymmetricBlockCipher.java

示例5: engineUpdate

import javax.crypto.ShortBufferException; //导入依赖的package包/类
protected int engineUpdate(
    byte[]  input,
    int     inputOffset,
    int     inputLen,
    byte[]  output,
    int     outputOffset) 
    throws ShortBufferException 
{
    try
    {
    cipher.processBytes(input, inputOffset, inputLen, output, outputOffset);

    return inputLen;
    }
    catch (DataLengthException e)
    {
        throw new ShortBufferException(e.getMessage());
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:BaseStreamCipher.java

示例6: main

import javax.crypto.ShortBufferException; //导入依赖的package包/类
public static void main(String[] args) throws ShortBufferException,
        IllegalBlockSizeException, BadPaddingException {
    byte[] plainText = new byte[801];
    // Initialization
    RandomFactory.getRandom().nextBytes(plainText);
    Cipher ci = new NullCipher();
    // Encryption
    byte[] cipherText = new byte[ci.getOutputSize(plainText.length)];
    int offset = ci.update(plainText, 0, plainText.length, cipherText, 0);
    ci.doFinal(cipherText, offset);
    // Decryption
    byte[] recoveredText = new byte[ci.getOutputSize(cipherText.length)];
    int len = ci.doFinal(cipherText, 0, cipherText.length, recoveredText);
    // Comparison
    if (len != plainText.length ||
            !TestUtilities.equalsBlock(plainText, cipherText, len) ||
            !TestUtilities.equalsBlock(plainText, recoveredText, len)) {
        throw new RuntimeException(
            "Test failed because plainText not equal to cipherText and revoveredText");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:CipherNCFuncTest.java

示例7: engineGenerateSecret

import javax.crypto.ShortBufferException; //导入依赖的package包/类
protected int engineGenerateSecret(
    byte[]  sharedSecret,
    int     offset) 
    throws IllegalStateException, ShortBufferException
{
    byte[] secret = engineGenerateSecret();

    if (sharedSecret.length - offset < secret.length)
    {
        throw new ShortBufferException(kaAlgorithm + " key agreement: need " + secret.length + " bytes");
    }

    System.arraycopy(secret, 0, sharedSecret, offset, secret.length);
    
    return secret.length;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:KeyAgreementSpi.java

示例8: engineTransformBlock

import javax.crypto.ShortBufferException; //导入依赖的package包/类
/**
 * This method is called whenever a full block needs to be
 * encrypted/decrypted. The input block is contained in input.The
 * transformed block is written into output starting at otputOfset. The
 * number of bytes written is returned.
 * 
 * @param input
 *            - byte[]
 * @param inputOffset
 *            -int
 * @param inputLenth
 *            -int
 * @param output
 *            -byte[]
 * @param outputOffset
 *            -int
 * @return The number of bytes written.
 * @throws ShortBufferException
 */
protected final int engineTransformBlock(byte[] input, int inputOffset,
		int inputLenth, byte[] output, int outputOffset)
		throws ShortBufferException {
	if (stateMode == Cipher.ENCRYPT_MODE)
		try {
			return encryptBlock(input, inputOffset, inputLenth, output,
					outputOffset);
		} catch (Exception e) {
			e.printStackTrace();
		}
	else if (stateMode == Cipher.DECRYPT_MODE)
		return decryptBlock(input, inputOffset, inputLenth, output,
				outputOffset);
	return 0;

}
 
开发者ID:peterstefanov,项目名称:paillier,代码行数:36,代码来源:PaillierCipher.java

示例9: engineDoFinal

import javax.crypto.ShortBufferException; //导入依赖的package包/类
/**
 * Calls the second overloaded version of the same method.
 */
protected final byte[] engineDoFinal(byte[] input, int inputOffset, int inputLen)
		throws IllegalBlockSizeException, BadPaddingException {
	int length = 0;
	byte[] out = new byte[engineGetOutputSize(inputLen)];
	try {
		length = engineDoFinal(input, inputOffset, inputLen, out, 0);
	} catch (ShortBufferException sbe) {

	}
	if (length < out.length) {
		byte[] smaller = new byte[length];
		System.arraycopy(out, 0, smaller, 0, length);
	}
	return out;
}
 
开发者ID:peterstefanov,项目名称:paillier,代码行数:19,代码来源:PaillierCipher.java

示例10: engineDoFinal

import javax.crypto.ShortBufferException; //导入依赖的package包/类
/**
 * Calls encrypt or decrypt based on the state of the cipher. Creates a
 * single input array from the supplied input data. And returns number of
 * bytes stored in output.
 * 
 * @param input
 *            - the input buffer
 * @param inputOffset
 *            - the offset in input where the input starts always zero
 * @param inputLen
 *            - the input length
 * @param output
 *            - the buffer for the result
 * @param outputOffset
 *            - the offset in output where the result is stored
 * @return the number of bytes stored in output
 */
protected final int engineDoFinal(byte[] input, int inputOffset, int inputLen,
		byte[] output, int outputOffset) throws ShortBufferException,
		IllegalBlockSizeException, BadPaddingException {
	// Create a single array of input data
	byte[] totalInput = new byte[inputLen ];
	if (inputLen > 0)
		System.arraycopy(input, inputOffset, totalInput, 0,
				inputLen);
	if (stateMode == Cipher.ENCRYPT_MODE)
		try {
			return encrypt(input, inputOffset, inputLen, output,
					outputOffset);
		} catch (Exception e) {
			e.printStackTrace();
		}
	else if (stateMode == Cipher.DECRYPT_MODE)
		return decrypt(input, inputOffset, inputLen, output,
				outputOffset);

	return 0;

}
 
开发者ID:peterstefanov,项目名称:paillier,代码行数:40,代码来源:PaillierHomomorphicCipher.java

示例11: runAll

import javax.crypto.ShortBufferException; //导入依赖的package包/类
public void runAll() throws InvalidKeyException,
        NoSuchPaddingException, InvalidAlgorithmParameterException,
        ShortBufferException, IllegalBlockSizeException,
        BadPaddingException, NoSuchAlgorithmException,
        NoSuchProviderException {

    for (String mode : MODES) {
        for (String padding : PADDINGS) {
            if (!isMultipleKeyLengthSupported()) {
                runTest(mode, padding, minKeySize);
            } else {
                int keySize = maxKeySize;
                while (keySize >= minKeySize) {
                    out.println("With Key Strength: " + keySize);
                    runTest(mode, padding, keySize);
                    keySize -= KEYCUTTER;
                }
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:TestCipher.java

示例12: padWithLen

import javax.crypto.ShortBufferException; //导入依赖的package包/类
/**
 * Adds the given number of padding bytes to the data input.
 * The value of the padding bytes is determined
 * by the specific padding mechanism that implements this
 * interface.
 *
 * @param in the input buffer with the data to pad
 * @param off the offset in <code>in</code> where the padding bytes
 * are appended
 * @param len the number of padding bytes to add
 *
 * @exception ShortBufferException if <code>in</code> is too small to hold
 * the padding bytes
 */
public void padWithLen(byte[] in, int off, int len)
    throws ShortBufferException
{
    if (in == null)
        return;

    if ((off + len) > in.length) {
        throw new ShortBufferException("Buffer too small to hold padding");
    }

    byte paddingOctet = (byte) (len & 0xff);
    byte[] padding = new byte[len];
    SunJCE.getRandom().nextBytes(padding);
    padding[len-1] = paddingOctet;
    System.arraycopy(padding, 0, in, off, len);
    return;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:32,代码来源:ISO10126Padding.java

示例13: padWithLen

import javax.crypto.ShortBufferException; //导入依赖的package包/类
/**
 * Adds the given number of padding bytes to the data input.
 * The value of the padding bytes is determined
 * by the specific padding mechanism that implements this
 * interface.
 *
 * @param in the input buffer with the data to pad
 * @param off the offset in <code>in</code> where the padding bytes
 * are appended
 * @param len the number of padding bytes to add
 *
 * @exception ShortBufferException if <code>in</code> is too small to hold
 * the padding bytes
 */
public void padWithLen(byte[] in, int off, int len)
    throws ShortBufferException
{
    if (in == null)
        return;

    if ((off + len) > in.length) {
        throw new ShortBufferException("Buffer too small to hold padding");
    }

    byte paddingOctet = (byte) (len & 0xff);
    for (int i = 0; i < len; i++) {
        in[i + off] = paddingOctet;
    }
    return;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:PKCS5Padding.java

示例14: hash

import javax.crypto.ShortBufferException; //导入依赖的package包/类
private byte[] hash(Cipher aes, byte[] h, byte[] nonce, byte[] plaintext, byte[] data) {
  final Polyval polyval = new Polyval(h);
  polyval.update(data); // hash data with padding
  polyval.update(plaintext); // hash plaintext with padding

  // hash data and plaintext lengths in bits with padding
  final byte[] block = new byte[AES_BLOCK_SIZE];
  Bytes.putLong((long) data.length * 8, block, 0);
  Bytes.putLong((long) plaintext.length * 8, block, 8);
  polyval.updateBlock(block, 0);

  polyval.digest(block);
  for (int i = 0; i < nonce.length; i++) {
    block[i] ^= nonce[i];
  }
  block[block.length - 1] &= (byte) ~0x80;

  // encrypt polyval hash to produce tag
  try {
    aes.update(block, 0, block.length, block, 0);
  } catch (ShortBufferException e) {
    throw new IllegalStateException(e);
  }
  return block;
}
 
开发者ID:codahale,项目名称:aes-gcm-siv,代码行数:26,代码来源:AEAD.java

示例15: subKey

import javax.crypto.ShortBufferException; //导入依赖的package包/类
private byte[] subKey(int ctrStart, int ctrEnd, byte[] nonce) {
  final byte[] counter = new byte[AES_BLOCK_SIZE];
  System.arraycopy(nonce, 0, counter, counter.length - nonce.length, nonce.length);
  final byte[] key = new byte[(ctrEnd - ctrStart + 1) * 8];
  final byte[] block = new byte[AES_BLOCK_SIZE];
  for (int i = ctrStart; i <= ctrEnd; i++) {
    Bytes.putInt(i, counter);
    try {
      aes.update(counter, 0, AES_BLOCK_SIZE, block, 0);
    } catch (ShortBufferException e) {
      throw new IllegalStateException(e);
    }
    System.arraycopy(block, 0, key, (i - ctrStart) * 8, 8);
  }
  return key;
}
 
开发者ID:codahale,项目名称:aes-gcm-siv,代码行数:17,代码来源:AEAD.java


注:本文中的javax.crypto.ShortBufferException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。