< prev index next > test/jdk/com/sun/crypto/provider/Cipher/ChaCha20/unittest/ChaCha20CipherUnitTest.java
Print this page
import java.security.AlgorithmParameters;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Arrays;
+ import java.util.Hex;
import javax.crypto.Cipher;
import javax.crypto.spec.ChaCha20ParameterSpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import jdk.test.lib.Utils;
public class ChaCha20CipherUnitTest {
private static final byte[] NONCE
- = Utils.toByteArray("012345670123456701234567");
+ = Hex.decoder().decode("012345670123456701234567");
private static final SecretKeySpec KEY = new SecretKeySpec(
- Utils.toByteArray(
- "0123456701234567012345670123456701234567012345670123456701234567"),
+ Hex.decoder().decode("0123456701234567012345670123456701234567012345670123456701234567"),
"ChaCha20");
private static final ChaCha20ParameterSpec CHACHA20_PARAM_SPEC
= new ChaCha20ParameterSpec(NONCE, 0);
private static final IvParameterSpec IV_PARAM_SPEC
= new IvParameterSpec(NONCE);
}
}
}
private static void testAEAD() throws Exception {
- byte[] expectedPlainttext = Utils.toByteArray("01234567");
+ byte[] expectedPlainttext = Hex.decoder().decode("01234567");
byte[] ciphertext = testUpdateAAD(Cipher.ENCRYPT_MODE, expectedPlainttext);
byte[] plaintext = testUpdateAAD(Cipher.DECRYPT_MODE, ciphertext);
if (!Arrays.equals(plaintext, expectedPlainttext)) {
System.out.println("ciphertext: " + Arrays.toString(ciphertext));
System.out.println("plaintext: " + Arrays.toString(plaintext));
private static byte[] testUpdateAAD(int opMode, byte[] input)
throws Exception {
String opModeName = getOpModeName(opMode);
System.out.println("== updateAAD (" + opModeName + ") ==");
- byte[] aad = Utils.toByteArray("0000");
+ byte[] aad = Hex.decoder().decode("0000");
ByteBuffer aadBuf = ByteBuffer.wrap(aad);
Cipher cipher = Cipher.getInstance("ChaCha20");
cipher.init(opMode, KEY, CHACHA20_PARAM_SPEC);
try {
< prev index next >