net.i2p.crypto
Class SigUtil

java.lang.Object
  extended by net.i2p.crypto.SigUtil

public class SigUtil
extends Object

Utilities for Signing keys and Signatures

Since:
0.9.9, public since 0.9.12

Method Summary
static void clearCaches()
           
static SigningPrivateKey fromJavaKey(DSAPrivateKey pk)
           
static SigningPublicKey fromJavaKey(DSAPublicKey pk)
           
static SigningPrivateKey fromJavaKey(ECPrivateKey pk, SigType type)
           
static SigningPublicKey fromJavaKey(ECPublicKey pk, SigType type)
           
static SigningPrivateKey fromJavaKey(EdDSAPrivateKey pk, SigType type)
           
static SigningPublicKey fromJavaKey(EdDSAPublicKey pk, SigType type)
           
static SigningPrivateKey fromJavaKey(PrivateKey pk)
          Use if SigType is unknown.
static SigningPrivateKey fromJavaKey(PrivateKey pk, SigType type)
          Use if SigType is known.
static SigningPublicKey fromJavaKey(PublicKey pk)
          Use if SigType is unknown.
static SigningPublicKey fromJavaKey(PublicKey pk, SigType type)
          Use if SigType is known.
static SigningPrivateKey fromJavaKey(RSAPrivateKey pk, SigType type)
          Deprecated. unused
static SigningPublicKey fromJavaKey(RSAPublicKey pk, SigType type)
           
static Signature fromJavaSig(byte[] asn, SigType type)
           
static PrivateKey importJavaPrivateKey(File file, SigType type)
           
static PublicKey importJavaPublicKey(File file, SigType type)
           
static byte[] rectify(BigInteger bi, int len)
           
static DSAPrivateKey toJavaDSAKey(SigningPrivateKey pk)
           
static DSAPublicKey toJavaDSAKey(SigningPublicKey pk)
           
static ECPrivateKey toJavaECKey(SigningPrivateKey pk)
           
static ECPublicKey toJavaECKey(SigningPublicKey pk)
           
static EdDSAPrivateKey toJavaEdDSAKey(SigningPrivateKey pk)
           
static EdDSAPublicKey toJavaEdDSAKey(SigningPublicKey pk)
           
static PrivateKey toJavaKey(SigningPrivateKey pk)
           
static PublicKey toJavaKey(SigningPublicKey pk)
           
static RSAPrivateKey toJavaRSAKey(SigningPrivateKey pk)
           
static RSAPublicKey toJavaRSAKey(SigningPublicKey pk)
          Deprecated. unused
static byte[] toJavaSig(Signature sig)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

toJavaKey

public static PublicKey toJavaKey(SigningPublicKey pk)
                           throws GeneralSecurityException
Returns:
JAVA key!
Throws:
GeneralSecurityException

toJavaKey

public static PrivateKey toJavaKey(SigningPrivateKey pk)
                            throws GeneralSecurityException
Returns:
JAVA key!
Throws:
GeneralSecurityException

fromJavaKey

public static SigningPublicKey fromJavaKey(PublicKey pk)
                                    throws GeneralSecurityException
Use if SigType is unknown. For efficiency, use fromJavakey(pk, type) if type is known.

Parameters:
pk - JAVA key!
Throws:
IllegalArgumentException - on unknown type
GeneralSecurityException
Since:
0.9.18

fromJavaKey

public static SigningPublicKey fromJavaKey(PublicKey pk,
                                           SigType type)
                                    throws GeneralSecurityException
Use if SigType is known.

Parameters:
pk - JAVA key!
Throws:
GeneralSecurityException

fromJavaKey

public static SigningPrivateKey fromJavaKey(PrivateKey pk)
                                     throws GeneralSecurityException
Use if SigType is unknown. For efficiency, use fromJavakey(pk, type) if type is known.

Parameters:
pk - JAVA key!
Throws:
IllegalArgumentException - on unknown type
GeneralSecurityException
Since:
0.9.18

fromJavaKey

public static SigningPrivateKey fromJavaKey(PrivateKey pk,
                                            SigType type)
                                     throws GeneralSecurityException
Use if SigType is known.

Parameters:
pk - JAVA key!
Throws:
GeneralSecurityException

toJavaECKey

public static ECPublicKey toJavaECKey(SigningPublicKey pk)
                               throws GeneralSecurityException
Returns:
JAVA key!
Throws:
GeneralSecurityException

toJavaECKey

public static ECPrivateKey toJavaECKey(SigningPrivateKey pk)
                                throws GeneralSecurityException
Returns:
JAVA key!
Throws:
GeneralSecurityException

fromJavaKey

public static SigningPublicKey fromJavaKey(ECPublicKey pk,
                                           SigType type)
                                    throws GeneralSecurityException
Throws:
GeneralSecurityException

fromJavaKey

public static SigningPrivateKey fromJavaKey(ECPrivateKey pk,
                                            SigType type)
                                     throws GeneralSecurityException
Throws:
GeneralSecurityException

toJavaEdDSAKey

public static EdDSAPublicKey toJavaEdDSAKey(SigningPublicKey pk)
                                     throws GeneralSecurityException
Returns:
JAVA EdDSA public key!
Throws:
GeneralSecurityException
Since:
0.9.15

toJavaEdDSAKey

public static EdDSAPrivateKey toJavaEdDSAKey(SigningPrivateKey pk)
                                      throws GeneralSecurityException
Returns:
JAVA EdDSA private key!
Throws:
GeneralSecurityException
Since:
0.9.15

fromJavaKey

public static SigningPublicKey fromJavaKey(EdDSAPublicKey pk,
                                           SigType type)
                                    throws GeneralSecurityException
Throws:
GeneralSecurityException
Since:
0.9.15

fromJavaKey

public static SigningPrivateKey fromJavaKey(EdDSAPrivateKey pk,
                                            SigType type)
                                     throws GeneralSecurityException
Throws:
GeneralSecurityException
Since:
0.9.15

toJavaDSAKey

public static DSAPublicKey toJavaDSAKey(SigningPublicKey pk)
                                 throws GeneralSecurityException
Throws:
GeneralSecurityException

toJavaDSAKey

public static DSAPrivateKey toJavaDSAKey(SigningPrivateKey pk)
                                  throws GeneralSecurityException
Throws:
GeneralSecurityException

fromJavaKey

public static SigningPublicKey fromJavaKey(DSAPublicKey pk)
                                    throws GeneralSecurityException
Throws:
GeneralSecurityException

fromJavaKey

public static SigningPrivateKey fromJavaKey(DSAPrivateKey pk)
                                     throws GeneralSecurityException
Throws:
GeneralSecurityException

toJavaRSAKey

public static RSAPublicKey toJavaRSAKey(SigningPublicKey pk)
                                 throws GeneralSecurityException
Deprecated. unused

Throws:
GeneralSecurityException

toJavaRSAKey

public static RSAPrivateKey toJavaRSAKey(SigningPrivateKey pk)
                                  throws GeneralSecurityException
Throws:
GeneralSecurityException

fromJavaKey

public static SigningPublicKey fromJavaKey(RSAPublicKey pk,
                                           SigType type)
                                    throws GeneralSecurityException
Throws:
GeneralSecurityException

fromJavaKey

public static SigningPrivateKey fromJavaKey(RSAPrivateKey pk,
                                            SigType type)
                                     throws GeneralSecurityException
Deprecated. unused

Throws:
GeneralSecurityException

toJavaSig

public static byte[] toJavaSig(Signature sig)
Returns:
ASN.1 representation

fromJavaSig

public static Signature fromJavaSig(byte[] asn,
                                    SigType type)
                             throws SignatureException
Parameters:
asn - ASN.1 representation
Returns:
a Signature with SigType type
Throws:
SignatureException

importJavaPublicKey

public static PublicKey importJavaPublicKey(File file,
                                            SigType type)
                                     throws GeneralSecurityException,
                                            IOException
Returns:
JAVA key!
Throws:
GeneralSecurityException
IOException

importJavaPrivateKey

public static PrivateKey importJavaPrivateKey(File file,
                                              SigType type)
                                       throws GeneralSecurityException,
                                              IOException
Returns:
JAVA key!
Throws:
GeneralSecurityException
IOException

rectify

public static byte[] rectify(BigInteger bi,
                             int len)
                      throws InvalidKeyException
Parameters:
bi - non-negative
Returns:
array of exactly len bytes
Throws:
InvalidKeyException

clearCaches

public static void clearCaches()