core.crypto
Class Signatures

java.lang.Object
  extended by core.crypto.Signatures

public class Signatures
extends Object

Provides easy access to all Signature stuff

  Copyright (c) 2006 Sebastian Erdweg
  Copyright (c) 2006 Dominik Schulz
  Copyright (c) 2006 Florian Lindner
  Copyright (c) 2006 Betim Berjani
  
  This file is part of FlexiCrypt.

  FlexiCrypt is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  FlexiCrypt is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with FlexiCrypt; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  

Author:
Sebastian, Dominik

Field Summary
static String HASH_ALGORITHM
           
 
Constructor Summary
Signatures()
           
 
Method Summary
static Set<String> getValidServices()
          Creates a list of valid signature algorithms
static boolean isValidSignatureAlgorithm(String algorithm)
           
static byte[] sign(byte[] tbs, PrivateKey privatekey, String sigAlgo)
          Sign a byte array
static void sign(File inputFile, File sigFile, KeyStore.PrivateKeyEntry entry)
          Simply sign a File.
static X509Certificate sign(X509Certificate userCert, KeyStore.PrivateKeyEntry caEntry)
          Signs the user cert with the CA's private key
static void signXML(File inputFile, File outputFile, KeyStore.PrivateKeyEntry entry, String sigAlgo)
          Sign a files hash and create an XML-Signature
static boolean verify(byte[] tbs, PublicKey pubKey, String sigAlg)
           
static boolean verify(File signedFile, File sigFile, X509Certificate cert)
          Verifies a signature created by the simple verify.
static boolean verify(X509Certificate cert)
           
static boolean verify(X509Certificate cert, PublicKey pubKey)
           
static boolean verifyXML(File inputFile)
          Read an XML-Signature, get the referenced file and compare the signed hashes and the signature
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HASH_ALGORITHM

public static final String HASH_ALGORITHM
See Also:
Constant Field Values
Constructor Detail

Signatures

public Signatures()
Method Detail

signXML

public static void signXML(File inputFile,
                           File outputFile,
                           KeyStore.PrivateKeyEntry entry,
                           String sigAlgo)
                    throws IOException,
                           NoSuchAlgorithmException,
                           InvalidKeyException,
                           InvalidAlgorithmParameterException,
                           InterruptedException,
                           SignatureException
Sign a files hash and create an XML-Signature

Parameters:
inputFile -
outputFile -
entry -
Throws:
IOException
NoSuchAlgorithmException
InvalidKeyException
InvalidAlgorithmParameterException
InterruptedException
SignatureException
See Also:
http://www.w3.org/TR/xmldsig-core/

verifyXML

public static boolean verifyXML(File inputFile)
                         throws Exception
Read an XML-Signature, get the referenced file and compare the signed hashes and the signature

Parameters:
inputFile -
Returns:
Throws:
Exception - TODO Hash-Algorithmus auslesen und verwenden
See Also:
http://www.w3.org/TR/xmldsig-core/

sign

public static void sign(File inputFile,
                        File sigFile,
                        KeyStore.PrivateKeyEntry entry)
                 throws Exception
Simply sign a File. This method works a seen in literature and many examples.

Parameters:
inputFile -
sigFile -
entry -
Throws:
Exception

sign

public static byte[] sign(byte[] tbs,
                          PrivateKey privatekey,
                          String sigAlgo)
                   throws NoSuchAlgorithmException,
                          SignatureException,
                          InvalidKeyException
Sign a byte array

Parameters:
tbs -
privatekey -
Returns:
Throws:
NoSuchAlgorithmException
SignatureException
InvalidKeyException

sign

public static X509Certificate sign(X509Certificate userCert,
                                   KeyStore.PrivateKeyEntry caEntry)
                            throws CertificateEncodingException,
                                   InvalidKeyException,
                                   NoSuchAlgorithmException,
                                   SignatureException
Signs the user cert with the CA's private key

Parameters:
certificate -
caCert -
Throws:
CertificateEncodingException
SignatureException
NoSuchAlgorithmException
InvalidKeyException

verify

public static boolean verify(File signedFile,
                             File sigFile,
                             X509Certificate cert)
                      throws Exception
Verifies a signature created by the simple verify.

Parameters:
signedFile -
sigFile -
cert -
Returns:
true iff signature is valid.
Throws:
Exception

verify

public static boolean verify(byte[] tbs,
                             PublicKey pubKey,
                             String sigAlg)
                      throws NoSuchAlgorithmException,
                             InvalidKeyException,
                             SignatureException
Throws:
NoSuchAlgorithmException
InvalidKeyException
SignatureException

verify

public static boolean verify(X509Certificate cert,
                             PublicKey pubKey)
                      throws NoSuchAlgorithmException,
                             InvalidKeyException,
                             CertificateEncodingException,
                             SignatureException
Throws:
NoSuchAlgorithmException
InvalidKeyException
CertificateEncodingException
SignatureException

verify

public static boolean verify(X509Certificate cert)
                      throws NoSuchAlgorithmException,
                             InvalidKeyException,
                             CertificateEncodingException,
                             SignatureException
Throws:
NoSuchAlgorithmException
InvalidKeyException
CertificateEncodingException
SignatureException

isValidSignatureAlgorithm

public static boolean isValidSignatureAlgorithm(String algorithm)
                                         throws NoSuchAlgorithmException,
                                                InvalidKeyException
Throws:
NoSuchAlgorithmException
InvalidKeyException

getValidServices

public static Set<String> getValidServices()
Creates a list of valid signature algorithms

Returns:
a set of valid signature algorithms