< prev index next >

src/java.base/share/classes/java/security/Signature.java

Print this page




  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.security;
  27 
  28 import java.security.spec.AlgorithmParameterSpec;
  29 import java.util.*;
  30 import java.util.concurrent.ConcurrentHashMap;
  31 import java.io.*;
  32 import java.security.cert.Certificate;
  33 import java.security.cert.X509Certificate;
  34 
  35 import java.nio.ByteBuffer;
  36 
  37 import java.security.Provider.Service;
  38 
  39 import javax.crypto.Cipher;
  40 import javax.crypto.CipherSpi;
  41 import javax.crypto.IllegalBlockSizeException;
  42 import javax.crypto.BadPaddingException;
  43 import javax.crypto.NoSuchPaddingException;
  44 
  45 import sun.security.util.Debug;
  46 import sun.security.jca.*;
  47 import sun.security.jca.GetInstance.Instance;
  48 
  49 /**
  50  * The Signature class is used to provide applications the functionality
  51  * of a digital signature algorithm. Digital signatures are used for
  52  * authentication and integrity assurance of digital data.
  53  *
  54  * <p> The signature algorithm can be, among others, the NIST standard
  55  * DSA, using DSA and SHA-1. The DSA algorithm using the
  56  * SHA-1 message digest algorithm can be specified as {@code SHA1withDSA}.
  57  * In the case of RSA, there are multiple choices for the message digest
  58  * algorithm, so the signing algorithm could be specified as, for example,
  59  * {@code MD2withRSA}, {@code MD5withRSA}, or {@code SHA1withRSA}.
  60  * The algorithm name must be specified, as there is no default.


 163     /**
 164      * Creates a Signature object for the specified algorithm.
 165      *
 166      * @param algorithm the standard string name of the algorithm.
 167      * See the Signature section in the <a href=
 168      * "{@docRoot}/../technotes/guides/security/StandardNames.html#Signature">
 169      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 170      * for information about standard algorithm names.
 171      */
 172     protected Signature(String algorithm) {
 173         this.algorithm = algorithm;
 174     }
 175 
 176     // name of the special signature alg
 177     private static final String RSA_SIGNATURE = "NONEwithRSA";
 178 
 179     // name of the equivalent cipher alg
 180     private static final String RSA_CIPHER = "RSA/ECB/PKCS1Padding";
 181 
 182     // all the services we need to lookup for compatibility with Cipher
 183     private static final List<ServiceId> rsaIds = Arrays.asList(
 184         new ServiceId[] {
 185             new ServiceId("Signature", "NONEwithRSA"),
 186             new ServiceId("Cipher", "RSA/ECB/PKCS1Padding"),
 187             new ServiceId("Cipher", "RSA/ECB"),
 188             new ServiceId("Cipher", "RSA//PKCS1Padding"),
 189             new ServiceId("Cipher", "RSA"),
 190         }
 191     );
 192 
 193     /**
 194      * Returns a Signature object that implements the specified signature
 195      * algorithm.
 196      *
 197      * <p> This method traverses the list of registered security Providers,
 198      * starting with the most preferred Provider.
 199      * A new Signature object encapsulating the
 200      * SignatureSpi implementation from the first
 201      * Provider that supports the specified algorithm is returned.
 202      *
 203      * <p> Note that the list of registered providers may be retrieved via
 204      * the {@link Security#getProviders() Security.getProviders()} method.
 205      *
 206      * @implNote
 207      * The JDK Reference Implementation additionally uses the
 208      * {@code jdk.security.provider.preferred}
 209      * {@link Security#getProperty(String) Security} property to determine
 210      * the preferred provider order for the specified algorithm. This
 211      * may be different than the order of providers returned by




  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.security;
  27 
  28 import java.security.spec.AlgorithmParameterSpec;
  29 import java.util.*;
  30 import java.util.concurrent.ConcurrentHashMap;
  31 import java.io.*;
  32 import java.security.cert.Certificate;
  33 import java.security.cert.X509Certificate;
  34 
  35 import java.nio.ByteBuffer;
  36 
  37 import java.security.Provider.Service;
  38 
  39 import javax.crypto.Cipher;

  40 import javax.crypto.IllegalBlockSizeException;
  41 import javax.crypto.BadPaddingException;
  42 import javax.crypto.NoSuchPaddingException;
  43 
  44 import sun.security.util.Debug;
  45 import sun.security.jca.*;
  46 import sun.security.jca.GetInstance.Instance;
  47 
  48 /**
  49  * The Signature class is used to provide applications the functionality
  50  * of a digital signature algorithm. Digital signatures are used for
  51  * authentication and integrity assurance of digital data.
  52  *
  53  * <p> The signature algorithm can be, among others, the NIST standard
  54  * DSA, using DSA and SHA-1. The DSA algorithm using the
  55  * SHA-1 message digest algorithm can be specified as {@code SHA1withDSA}.
  56  * In the case of RSA, there are multiple choices for the message digest
  57  * algorithm, so the signing algorithm could be specified as, for example,
  58  * {@code MD2withRSA}, {@code MD5withRSA}, or {@code SHA1withRSA}.
  59  * The algorithm name must be specified, as there is no default.


 162     /**
 163      * Creates a Signature object for the specified algorithm.
 164      *
 165      * @param algorithm the standard string name of the algorithm.
 166      * See the Signature section in the <a href=
 167      * "{@docRoot}/../technotes/guides/security/StandardNames.html#Signature">
 168      * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
 169      * for information about standard algorithm names.
 170      */
 171     protected Signature(String algorithm) {
 172         this.algorithm = algorithm;
 173     }
 174 
 175     // name of the special signature alg
 176     private static final String RSA_SIGNATURE = "NONEwithRSA";
 177 
 178     // name of the equivalent cipher alg
 179     private static final String RSA_CIPHER = "RSA/ECB/PKCS1Padding";
 180 
 181     // all the services we need to lookup for compatibility with Cipher
 182     private static final List<ServiceId> rsaIds = List.of(

 183         new ServiceId("Signature", "NONEwithRSA"),
 184         new ServiceId("Cipher", "RSA/ECB/PKCS1Padding"),
 185         new ServiceId("Cipher", "RSA/ECB"),
 186         new ServiceId("Cipher", "RSA//PKCS1Padding"),
 187         new ServiceId("Cipher", "RSA"));


 188 
 189     /**
 190      * Returns a Signature object that implements the specified signature
 191      * algorithm.
 192      *
 193      * <p> This method traverses the list of registered security Providers,
 194      * starting with the most preferred Provider.
 195      * A new Signature object encapsulating the
 196      * SignatureSpi implementation from the first
 197      * Provider that supports the specified algorithm is returned.
 198      *
 199      * <p> Note that the list of registered providers may be retrieved via
 200      * the {@link Security#getProviders() Security.getProviders()} method.
 201      *
 202      * @implNote
 203      * The JDK Reference Implementation additionally uses the
 204      * {@code jdk.security.provider.preferred}
 205      * {@link Security#getProperty(String) Security} property to determine
 206      * the preferred provider order for the specified algorithm. This
 207      * may be different than the order of providers returned by


< prev index next >