當前位置: 首頁>>代碼示例>>Java>>正文


Java ShortBufferException.printStackTrace方法代碼示例

本文整理匯總了Java中javax.crypto.ShortBufferException.printStackTrace方法的典型用法代碼示例。如果您正苦於以下問題:Java ShortBufferException.printStackTrace方法的具體用法?Java ShortBufferException.printStackTrace怎麽用?Java ShortBufferException.printStackTrace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.crypto.ShortBufferException的用法示例。


在下文中一共展示了ShortBufferException.printStackTrace方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateSecret

import javax.crypto.ShortBufferException; //導入方法依賴的package包/類
public byte[] generateSecret() throws IllegalStateException {
    byte[] sharedSecret = new byte[KEY_SIZE];
    try {
        generateSecret(sharedSecret, 0);
    } catch (ShortBufferException e) {
        e.printStackTrace();
    }
    return sharedSecret;
}
 
開發者ID:Alezhka,項目名稱:JWaves,代碼行數:10,代碼來源:Curve25519KeyAgreement.java

示例2: updateShouldMatchUsingByteByffer

import javax.crypto.ShortBufferException; //導入方法依賴的package包/類
@Test(expected=ShortBufferException.class)
public void updateShouldMatchUsingByteByffer() throws ShortBufferException {
	String[] keys = new String[] {
			"e61a38548694f1fd8cef251c518cc70bb613751c1ce52aa8",
			"2ff4e5c1cda84946798cc4ea8a1cf8df579e8a70f438b554",
			"9151232c854cf7977562a4e098d9d6ce892a80f79b408934",
			"9715c173b0a89292b3a88acbc7522085d5a1522f32109ea1" };
	String[] ivs = new String[] { "48a8ceb8551fd4ad",
			"76b779525bb0d1c0", "0e04ab4e1171451d", "19e6a2b2a690f026" };
	String[] inputs = new String[] { "e8fb0ceb4e912e16",
			"77340331c9c8e4f4", "2dab916e1b72c578", "7a3d5228d200e322" };
	String[] outputs = new String[] { "d2190e296a0bfc56",
			"b7f1fd226680a6ee", "f50d41fc9fe9ba71", "5e124bc1d28414e7" };


	ByteBuffer input = ByteBuffer.allocateDirect(Des3.BLOCK_SIZE);
	ByteBuffer output = ByteBuffer.allocateDirect(Des3.BLOCK_SIZE);
	ByteBuffer plain = ByteBuffer.allocateDirect(Des3.BLOCK_SIZE);
	ByteBuffer cipher = ByteBuffer.allocateDirect(Des3.BLOCK_SIZE);

	for (int i = 0; i < inputs.length; i++) {
		Des3 enc = new Des3(Util.h2b(keys[i]), Util.h2b(ivs[i]),
				Des3.ENCRYPT_MODE);
		Des3 dec = new Des3(Util.h2b(keys[i]), Util.h2b(ivs[i]),
				Des3.DECRYPT_MODE);

		input.put(Util.h2b(inputs[i])).rewind();
		output.put(Util.h2b(outputs[i])).rewind();

		try {
			assertEquals(Des3.BLOCK_SIZE, enc.update(input, cipher));
			assertEquals(Des3.BLOCK_SIZE, dec.update(output, plain));
		} catch (ShortBufferException e) {
			e.printStackTrace();
			fail();
		}

		assertEquals(Des3.BLOCK_SIZE, input.position());
		assertEquals(0, input.remaining());
		assertEquals(Des3.BLOCK_SIZE, output.position());
		assertEquals(0, output.remaining());
		assertEquals(Des3.BLOCK_SIZE, cipher.position());
		assertEquals(0, cipher.remaining());
		assertEquals(Des3.BLOCK_SIZE, plain.position());
		assertEquals(0, plain.remaining());

		input.rewind();
		output.rewind();
		cipher.rewind();
		plain.rewind();

		assertEquals(output, cipher);
		assertEquals(input, plain);
		
		/* tests ShortBufferException */
		if (i == inputs.length - 1) {
			cipher.position(cipher.limit());
			enc.update(input, cipher);
		}
	}
}
 
開發者ID:wolfSSL,項目名稱:wolfcrypt-jni,代碼行數:62,代碼來源:Des3Test.java

示例3: updateShouldMatchUsingByteArray

import javax.crypto.ShortBufferException; //導入方法依賴的package包/類
@Test(expected=ShortBufferException.class)
public void updateShouldMatchUsingByteArray() throws ShortBufferException {
	String[] keys = new String[] {
			"e61a38548694f1fd8cef251c518cc70bb613751c1ce52aa8",
			"2ff4e5c1cda84946798cc4ea8a1cf8df579e8a70f438b554",
			"9151232c854cf7977562a4e098d9d6ce892a80f79b408934",
			"9715c173b0a89292b3a88acbc7522085d5a1522f32109ea1" };
	String[] ivs = new String[] { "48a8ceb8551fd4ad",
			"76b779525bb0d1c0", "0e04ab4e1171451d", "19e6a2b2a690f026" };
	String[] inputs = new String[] { "e8fb0ceb4e912e16",
			"77340331c9c8e4f4", "2dab916e1b72c578", "7a3d5228d200e322" };
	String[] outputs = new String[] { "d2190e296a0bfc56",
			"b7f1fd226680a6ee", "f50d41fc9fe9ba71", "5e124bc1d28414e7" };

	for (int i = 0; i < inputs.length; i++) {
		Des3 enc = new Des3(Util.h2b(keys[i]), Util.h2b(ivs[i]),
				Des3.ENCRYPT_MODE);
		Des3 dec = new Des3(Util.h2b(keys[i]), Util.h2b(ivs[i]),
				Des3.DECRYPT_MODE);

		byte[] input = Util.h2b(inputs[i]);
		byte[] output = Util.h2b(outputs[i]);
		byte[] cipher = new byte[Des3.BLOCK_SIZE];
		byte[] plain = new byte[Des3.BLOCK_SIZE];

		if (i % 2 == 0) {
			cipher = enc.update(input, 0, input.length);
			plain = dec.update(output, 0, output.length);
		} else {
			try {
				assertEquals(Des3.BLOCK_SIZE,
						enc.update(input, 0, input.length, cipher, 0));
				assertEquals(Des3.BLOCK_SIZE,
						dec.update(output, 0, output.length, plain, 0));
			} catch (ShortBufferException e) {
				e.printStackTrace();
				fail();
			}
		}

		assertArrayEquals(output, cipher);
		assertArrayEquals(input, plain);
		
		/* tests ShortBufferException */
		if (i == inputs.length - 1)
			enc.update(input, 0, input.length, cipher, Des3.BLOCK_SIZE);
	}
}
 
開發者ID:wolfSSL,項目名稱:wolfcrypt-jni,代碼行數:49,代碼來源:Des3Test.java


注:本文中的javax.crypto.ShortBufferException.printStackTrace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。