< prev index next >

test/jdk/com/sun/crypto/provider/Cipher/ChaCha20/ChaCha20KeyGeneratorTest.java

Print this page
*** 28,25 ***
   * @library /test/lib
   */
  
  import java.security.InvalidAlgorithmParameterException;
  import java.security.InvalidParameterException;
  
  import javax.crypto.KeyGenerator;
  import javax.crypto.SecretKey;
  import javax.crypto.spec.ChaCha20ParameterSpec;
  
- import jdk.test.lib.Utils;
- 
  public class ChaCha20KeyGeneratorTest {
  
      public static void main(String[] args) throws Exception {
          KeyGenerator generator = KeyGenerator.getInstance("ChaCha20");
  
          try {
              generator.init(new ChaCha20ParameterSpec(
!                     Utils.toByteArray("100000000000000000000000"), 0));
              throw new RuntimeException(
                      "ChaCha20 key generation should not consume AlgorithmParameterSpec");
          } catch (InvalidAlgorithmParameterException e) {
              System.out.println("Expected InvalidAlgorithmParameterException: "
                      + e.getMessage());
--- 28,24 ---
   * @library /test/lib
   */
  
  import java.security.InvalidAlgorithmParameterException;
  import java.security.InvalidParameterException;
+ import java.util.Hex;
  
  import javax.crypto.KeyGenerator;
  import javax.crypto.SecretKey;
  import javax.crypto.spec.ChaCha20ParameterSpec;
  
  public class ChaCha20KeyGeneratorTest {
  
      public static void main(String[] args) throws Exception {
          KeyGenerator generator = KeyGenerator.getInstance("ChaCha20");
  
          try {
              generator.init(new ChaCha20ParameterSpec(
!                     Hex.decoder().decode("100000000000000000000000"), 0));
              throw new RuntimeException(
                      "ChaCha20 key generation should not consume AlgorithmParameterSpec");
          } catch (InvalidAlgorithmParameterException e) {
              System.out.println("Expected InvalidAlgorithmParameterException: "
                      + e.getMessage());

*** 63,11 ***
          }
  
          generator.init(256);
          SecretKey key = generator.generateKey();
          byte[] keyValue = key.getEncoded();
!         System.out.println("Key: " + Utils.toHexString(keyValue));
          if (keyValue.length != 32) {
              throw new RuntimeException("The size of generated key must be 256");
          }
      }
  }
--- 62,11 ---
          }
  
          generator.init(256);
          SecretKey key = generator.generateKey();
          byte[] keyValue = key.getEncoded();
!         System.out.println("Key: " + Hex.encoder().encode(keyValue));
          if (keyValue.length != 32) {
              throw new RuntimeException("The size of generated key must be 256");
          }
      }
  }
< prev index next >