當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。