src/share/classes/sun/security/rsa/RSASignature.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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 sun.security.rsa;
  27 
  28 import java.io.IOException;
  29 import java.nio.ByteBuffer;
  30 import java.math.BigInteger;
  31 import java.util.Arrays;
  32 
  33 import java.security.*;
  34 import java.security.interfaces.*;
  35 
  36 import sun.security.util.*;
  37 import sun.security.x509.AlgorithmId;
  38 
  39 /**
  40  * PKCS#1 RSA signatures with the various message digest algorithms.
  41  * This file contains an abstract base class with all the logic plus
  42  * a nested static class for each of the message digest algorithms
  43  * (see end of the file). We support MD2, MD5, SHA-1, SHA-256, SHA-384,
  44  * and SHA-512.
  45  *
  46  * @since   1.5
  47  * @author  Andreas Sterbenz
  48  */
  49 public abstract class RSASignature extends SignatureSpi {
  50 
  51     // we sign an ASN.1 SEQUENCE of AlgorithmId and digest
  52     // it has the form 30:xx:30:xx:[digestOID]:05:00:04:xx:[digest]
  53     // this means the encoded length is (8 + digestOID.length + digest.length)
  54     private static final int baseLength = 8;
  55 
  56     // object identifier for the message digest algorithm used
  57     private final ObjectIdentifier digestOID;
  58 
  59     // length of the encoded signature blob
  60     private final int encodedLength;
  61 
  62     // message digest implementation we use
  63     private final MessageDigest md;
  64     // flag indicating whether the digest is reset


 259     }
 260 
 261     // Nested class for MD2withRSA signatures
 262     public static final class MD2withRSA extends RSASignature {
 263         public MD2withRSA() {
 264             super("MD2", AlgorithmId.MD2_oid, 10);
 265         }
 266     }
 267 
 268     // Nested class for MD5withRSA signatures
 269     public static final class MD5withRSA extends RSASignature {
 270         public MD5withRSA() {
 271             super("MD5", AlgorithmId.MD5_oid, 10);
 272         }
 273     }
 274 
 275     // Nested class for SHA1withRSA signatures
 276     public static final class SHA1withRSA extends RSASignature {
 277         public SHA1withRSA() {
 278             super("SHA-1", AlgorithmId.SHA_oid, 7);







 279         }
 280     }
 281 
 282     // Nested class for SHA256withRSA signatures
 283     public static final class SHA256withRSA extends RSASignature {
 284         public SHA256withRSA() {
 285             super("SHA-256", AlgorithmId.SHA256_oid, 11);
 286         }
 287     }
 288 
 289     // Nested class for SHA384withRSA signatures
 290     public static final class SHA384withRSA extends RSASignature {
 291         public SHA384withRSA() {
 292             super("SHA-384", AlgorithmId.SHA384_oid, 11);
 293         }
 294     }
 295 
 296     // Nested class for SHA512withRSA signatures
 297     public static final class SHA512withRSA extends RSASignature {
 298         public SHA512withRSA() {
   1 /*
   2  * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  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 sun.security.rsa;
  27 
  28 import java.io.IOException;
  29 import java.nio.ByteBuffer;
  30 import java.math.BigInteger;
  31 import java.util.Arrays;
  32 
  33 import java.security.*;
  34 import java.security.interfaces.*;
  35 
  36 import sun.security.util.*;
  37 import sun.security.x509.AlgorithmId;
  38 
  39 /**
  40  * PKCS#1 RSA signatures with the various message digest algorithms.
  41  * This file contains an abstract base class with all the logic plus
  42  * a nested static class for each of the message digest algorithms
  43  * (see end of the file). We support MD2, MD5, SHA-1, SHA-224, SHA-256,
  44  * SHA-384, and SHA-512.
  45  *
  46  * @since   1.5
  47  * @author  Andreas Sterbenz
  48  */
  49 public abstract class RSASignature extends SignatureSpi {
  50 
  51     // we sign an ASN.1 SEQUENCE of AlgorithmId and digest
  52     // it has the form 30:xx:30:xx:[digestOID]:05:00:04:xx:[digest]
  53     // this means the encoded length is (8 + digestOID.length + digest.length)
  54     private static final int baseLength = 8;
  55 
  56     // object identifier for the message digest algorithm used
  57     private final ObjectIdentifier digestOID;
  58 
  59     // length of the encoded signature blob
  60     private final int encodedLength;
  61 
  62     // message digest implementation we use
  63     private final MessageDigest md;
  64     // flag indicating whether the digest is reset


 259     }
 260 
 261     // Nested class for MD2withRSA signatures
 262     public static final class MD2withRSA extends RSASignature {
 263         public MD2withRSA() {
 264             super("MD2", AlgorithmId.MD2_oid, 10);
 265         }
 266     }
 267 
 268     // Nested class for MD5withRSA signatures
 269     public static final class MD5withRSA extends RSASignature {
 270         public MD5withRSA() {
 271             super("MD5", AlgorithmId.MD5_oid, 10);
 272         }
 273     }
 274 
 275     // Nested class for SHA1withRSA signatures
 276     public static final class SHA1withRSA extends RSASignature {
 277         public SHA1withRSA() {
 278             super("SHA-1", AlgorithmId.SHA_oid, 7);
 279         }
 280     }
 281 
 282     // Nested class for SHA224withRSA signatures
 283     public static final class SHA224withRSA extends RSASignature {
 284         public SHA224withRSA() {
 285             super("SHA-224", AlgorithmId.SHA224_oid, 11);
 286         }
 287     }
 288 
 289     // Nested class for SHA256withRSA signatures
 290     public static final class SHA256withRSA extends RSASignature {
 291         public SHA256withRSA() {
 292             super("SHA-256", AlgorithmId.SHA256_oid, 11);
 293         }
 294     }
 295 
 296     // Nested class for SHA384withRSA signatures
 297     public static final class SHA384withRSA extends RSASignature {
 298         public SHA384withRSA() {
 299             super("SHA-384", AlgorithmId.SHA384_oid, 11);
 300         }
 301     }
 302 
 303     // Nested class for SHA512withRSA signatures
 304     public static final class SHA512withRSA extends RSASignature {
 305         public SHA512withRSA() {