Package net.i2p.crypto
Class SigUtil
java.lang.Object
net.i2p.crypto.SigUtil
public final class SigUtil extends Object
Utilities for Signing keys and Signatures
- Since:
- 0.9.9, public since 0.9.12
-
Method Summary
Modifier and Type Method Description static NativeBigInteger[]aSN1ToBigInteger(byte[] asn, int len)See above.static voidclearCaches()(package private) static byte[]combine(BigInteger x, BigInteger y, int len)Combine two BigIntegers of nominal length = len / 2static SigningPrivateKeyfromJavaKey(DSAPrivateKey pk)static SigningPublicKeyfromJavaKey(DSAPublicKey pk)static SigningPrivateKeyfromJavaKey(ECPrivateKey pk, SigType type)static SigningPublicKeyfromJavaKey(ECPublicKey pk, SigType type)static SigningPrivateKeyfromJavaKey(RSAPrivateKey pk, SigType type)As of 0.9.31, if pk is a RSAPrivateCrtKey, this will return a RSASigningPrivateCrtKey.static SigningPublicKeyfromJavaKey(RSAPublicKey pk, SigType type)static SigningPrivateKeyfromJavaKey(PrivateKey pk)Use if SigType is unknown.static SigningPrivateKeyfromJavaKey(PrivateKey pk, SigType type)Use if SigType is known.static SigningPublicKeyfromJavaKey(PublicKey pk)Use if SigType is unknown.static SigningPublicKeyfromJavaKey(PublicKey pk, SigType type)Use if SigType is known.static SigningPrivateKeyfromJavaKey(EdDSAPrivateKey pk, SigType type)static SigningPublicKeyfromJavaKey(EdDSAPublicKey pk, SigType type)static SignaturefromJavaSig(byte[] asn, SigType type)static PrivateKeyimportJavaPrivateKey(File file, SigType type)static PublicKeyimportJavaPublicKey(File file, SigType type)static intintToASN1(byte[] d, int idx, int val)Output an length or integer value in ASN.1 Does NOT output the tag e.g.static byte[]rectify(BigInteger bi, int len)static byte[]sigBytesToASN1(BigInteger r, BigInteger s)http://download.oracle.com/javase/1.5.0/docs/guide/security/CryptoSpec.htmlstatic DSAPrivateKeytoJavaDSAKey(SigningPrivateKey pk)static DSAPublicKeytoJavaDSAKey(SigningPublicKey pk)static ECPrivateKeytoJavaECKey(SigningPrivateKey pk)static ECPublicKeytoJavaECKey(SigningPublicKey pk)static EdDSAPrivateKeytoJavaEdDSAKey(SigningPrivateKey pk)static EdDSAPublicKeytoJavaEdDSAKey(SigningPublicKey pk)static PrivateKeytoJavaKey(SigningPrivateKey pk)static PublicKeytoJavaKey(SigningPublicKey pk)static RSAPrivateKeytoJavaRSAKey(SigningPrivateKey pk)As of 0.9.31, if pk is a RSASigningPrivateCrtKey, this will return a RSAPrivateCrtKey.static RSAPublicKeytoJavaRSAKey(SigningPublicKey pk)Deprecated.unusedstatic byte[]toJavaSig(Signature sig)
-
Method Details
-
toJavaKey
- Returns:
- JAVA key!
- Throws:
GeneralSecurityException
-
toJavaKey
- Returns:
- JAVA key!
- Throws:
GeneralSecurityException
-
fromJavaKey
Use if SigType is unknown. For efficiency, use fromJavakey(pk, type) if type is known.- Parameters:
pk- JAVA key!- Throws:
IllegalArgumentException- on unknown typeGeneralSecurityException- Since:
- 0.9.18
-
fromJavaKey
public static SigningPublicKey fromJavaKey(PublicKey pk, SigType type) throws GeneralSecurityExceptionUse if SigType is known.- Parameters:
pk- JAVA key!- Throws:
GeneralSecurityException
-
fromJavaKey
Use if SigType is unknown. For efficiency, use fromJavakey(pk, type) if type is known.- Parameters:
pk- JAVA key!- Throws:
IllegalArgumentException- on unknown typeGeneralSecurityException- Since:
- 0.9.18
-
fromJavaKey
public static SigningPrivateKey fromJavaKey(PrivateKey pk, SigType type) throws GeneralSecurityExceptionUse if SigType is known.- Parameters:
pk- JAVA key!- Throws:
GeneralSecurityException
-
toJavaECKey
- Returns:
- JAVA key!
- Throws:
GeneralSecurityException
-
toJavaECKey
- 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
- Returns:
- JAVA EdDSA public key!
- Throws:
GeneralSecurityException- Since:
- 0.9.15
-
toJavaEdDSAKey
- 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
- Throws:
GeneralSecurityException
-
toJavaDSAKey
- Throws:
GeneralSecurityException
-
fromJavaKey
- Throws:
GeneralSecurityException
-
fromJavaKey
- Throws:
GeneralSecurityException
-
toJavaRSAKey
Deprecated.unused- Throws:
GeneralSecurityException
-
toJavaRSAKey
As of 0.9.31, if pk is a RSASigningPrivateCrtKey, this will return a RSAPrivateCrtKey.- 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 GeneralSecurityExceptionAs of 0.9.31, if pk is a RSAPrivateCrtKey, this will return a RSASigningPrivateCrtKey.- Throws:
GeneralSecurityException
-
toJavaSig
- Returns:
- ASN.1 representation
-
fromJavaSig
- 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:
GeneralSecurityExceptionIOException
-
importJavaPrivateKey
public static PrivateKey importJavaPrivateKey(File file, SigType type) throws GeneralSecurityException, IOException- Returns:
- JAVA key!
- Throws:
GeneralSecurityExceptionIOException
-
combine
Combine two BigIntegers of nominal length = len / 2- Returns:
- array of exactly len bytes
- Throws:
InvalidKeyException- Since:
- 0.9.9, package private since 0.9.31
-
rectify
- Parameters:
bi- non-negative- Returns:
- array of exactly len bytes
- Throws:
InvalidKeyException
-
sigBytesToASN1
http://download.oracle.com/javase/1.5.0/docs/guide/security/CryptoSpec.htmlSignature Format: ASN.1 sequence of two INTEGER values: r and s, in that order: SEQUENCE ::= { r INTEGER, s INTEGER } http://en.wikipedia.org/wiki/Abstract_Syntax_Notation_One 30 -- tag indicating SEQUENCE xx - length in octets 02 -- tag indicating INTEGER xx - length in octets xxxxxx - valuer and s are always non-negative. Only supports sigs up to about 65530 bytes. See code to fix BER encoding for this before you add a SigType with bigger signatures.- Throws:
IllegalArgumentException- if too big- Since:
- 0.9.25, split out from sigBytesToASN1(byte[])
-
intToASN1
public static int intToASN1(byte[] d, int idx, int val)Output an length or integer value in ASN.1 Does NOT output the tag e.g. 0x02 / 0x30- Parameters:
val- 0-65535- Returns:
- the new index
- Since:
- 0.9.25
-
aSN1ToBigInteger
See above. Only supports sigs up to about 65530 bytes. See code to fix BER encoding for bigger than that.- Parameters:
len- nominal length of each BigInteger- Returns:
- two BigIntegers
- Throws:
SignatureException- Since:
- 0.9.25
-
clearCaches
public static void clearCaches()
-