jdk/src/java.base/share/classes/javax/crypto/KeyGenerator.java
changeset 26736 5a93000b26cd
parent 25859 3317bb8137f4
child 26861 47dde7f5cf36
equal deleted inserted replaced
26735:4502faa0cc22 26736:5a93000b26cd
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    31 import java.security.Provider.Service;
    31 import java.security.Provider.Service;
    32 import java.security.spec.*;
    32 import java.security.spec.*;
    33 
    33 
    34 import sun.security.jca.*;
    34 import sun.security.jca.*;
    35 import sun.security.jca.GetInstance.Instance;
    35 import sun.security.jca.GetInstance.Instance;
       
    36 import sun.security.util.Debug;
    36 
    37 
    37 /**
    38 /**
    38  * This class provides the functionality of a secret (symmetric) key generator.
    39  * This class provides the functionality of a secret (symmetric) key generator.
    39  *
    40  *
    40  * <p>Key generators are constructed using one of the <code>getInstance</code>
    41  * <p>Key generators are constructed using one of the <code>getInstance</code>
   106  * @since 1.4
   107  * @since 1.4
   107  */
   108  */
   108 
   109 
   109 public class KeyGenerator {
   110 public class KeyGenerator {
   110 
   111 
       
   112     private static final Debug pdebug =
       
   113                         Debug.getInstance("provider", "Provider");
       
   114     private static final boolean skipDebug =
       
   115         Debug.isOn("engine=") && !Debug.isOn("keygenerator");
       
   116 
   111     // see java.security.KeyPairGenerator for failover notes
   117     // see java.security.KeyPairGenerator for failover notes
   112 
   118 
   113     private final static int I_NONE   = 1;
   119     private final static int I_NONE   = 1;
   114     private final static int I_RANDOM = 2;
   120     private final static int I_RANDOM = 2;
   115     private final static int I_PARAMS = 3;
   121     private final static int I_PARAMS = 3;
   143     protected KeyGenerator(KeyGeneratorSpi keyGenSpi, Provider provider,
   149     protected KeyGenerator(KeyGeneratorSpi keyGenSpi, Provider provider,
   144                            String algorithm) {
   150                            String algorithm) {
   145         this.spi = keyGenSpi;
   151         this.spi = keyGenSpi;
   146         this.provider = provider;
   152         this.provider = provider;
   147         this.algorithm = algorithm;
   153         this.algorithm = algorithm;
       
   154 
       
   155         if (!skipDebug && pdebug != null) {
       
   156             pdebug.println("KeyGenerator." + algorithm + " algorithm from: " +
       
   157                 this.provider.getName());
       
   158         }
   148     }
   159     }
   149 
   160 
   150     private KeyGenerator(String algorithm) throws NoSuchAlgorithmException {
   161     private KeyGenerator(String algorithm) throws NoSuchAlgorithmException {
   151         this.algorithm = algorithm;
   162         this.algorithm = algorithm;
   152         List<Service> list =
   163         List<Service> list =
   155         initType = I_NONE;
   166         initType = I_NONE;
   156         // fetch and instantiate initial spi
   167         // fetch and instantiate initial spi
   157         if (nextSpi(null, false) == null) {
   168         if (nextSpi(null, false) == null) {
   158             throw new NoSuchAlgorithmException
   169             throw new NoSuchAlgorithmException
   159                 (algorithm + " KeyGenerator not available");
   170                 (algorithm + " KeyGenerator not available");
       
   171         }
       
   172 
       
   173         if (!skipDebug && pdebug != null) {
       
   174             pdebug.println("KeyGenerator." + algorithm + " algorithm from: " +
       
   175                 this.provider.getName());
   160         }
   176         }
   161     }
   177     }
   162 
   178 
   163     /**
   179     /**
   164      * Returns the algorithm name of this <code>KeyGenerator</code> object.
   180      * Returns the algorithm name of this <code>KeyGenerator</code> object.