public final class SigUtil extends Object
Key functionalities include:
| Modifier and Type | Method and Description |
|---|---|
static NativeBigInteger[] | aSN1ToBigInteger(byte[] asn,
int len)See above. |
static void | clearCaches()Clear all cached Java key conversions. |
(package private) static byte[] | combine(BigInteger x,
BigInteger y,
int len)Combine two BigIntegers of nominal length = len / 2 |
static SigningPrivateKey | fromJavaKey(DSAPrivateKey pk)Convert a Java DSAPrivateKey to an I2P DSA private key. |
static SigningPublicKey | fromJavaKey(DSAPublicKey pk)Convert a Java DSAPublicKey to an I2P DSA public key. |
static SigningPrivateKey | fromJavaKey(ECPrivateKey pk,
SigType type)Convert a Java ECPrivateKey to an I2P SigningPrivateKey of the given type. |
static SigningPublicKey | fromJavaKey(ECPublicKey pk,
SigType type)Convert a Java ECPublicKey to an I2P SigningPublicKey of the given type. |
static SigningPrivateKey | fromJavaKey(EdDSAPrivateKey pk,
SigType type)Convert a Java EdDSAPrivateKey to an I2P SigningPrivateKey. |
static SigningPublicKey | fromJavaKey(EdDSAPublicKey pk,
SigType type)Convert a Java EdDSAPublicKey to an I2P SigningPublicKey. |
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)Convert a Java RSAPrivateKey to an I2P RSA private key of the given type. |
static SigningPublicKey | fromJavaKey(RSAPublicKey pk,
SigType type)Convert a Java RSAPublicKey to an I2P RSA public key of the given type. |
static Signature | fromJavaSig(byte[] asn,
SigType type)Convert a Java ASN.1 signature byte array to an I2P Signature. |
static PrivateKey | importJavaPrivateKey(File file,
SigType type)Import a Java PKCS8-encoded private key from a file. |
static PublicKey | importJavaPublicKey(File file,
SigType type)Import a Java X.509-encoded public key from a file. |
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. |
static byte[] | rectify(BigInteger bi,
int len)Convert a BigInteger to a fixed-length byte array, trimming or zero-padding as needed. |
static byte[] | sigBytesToASN1(BigInteger r,
BigInteger s)http://download.oracle.com/javase/1.5.0/docs/guide/security/CryptoSpec.html |
static DSAPrivateKey | toJavaDSAKey(SigningPrivateKey pk)Convert an I2P DSA private key to a Java DSAPrivateKey. |
static DSAPublicKey | toJavaDSAKey(SigningPublicKey pk)Convert an I2P DSA public key to a Java DSAPublicKey. |
static ECPrivateKey | toJavaECKey(SigningPrivateKey pk)Convert an I2P EC private key to a Java ECPrivateKey, with caching. |
static ECPublicKey | toJavaECKey(SigningPublicKey pk)Convert an I2P EC public key to a Java ECPublicKey, with caching. |
static EdDSAPrivateKey | toJavaEdDSAKey(SigningPrivateKey pk)Convert an I2P EdDSA private key to a Java EdDSAPrivateKey, with caching. |
static EdDSAPublicKey | toJavaEdDSAKey(SigningPublicKey pk)Convert an I2P EdDSA public key to a Java EdDSAPublicKey, with caching. |
static PrivateKey | toJavaKey(SigningPrivateKey pk)Convert an I2P SigningPrivateKey to a Java PrivateKey, dispatching by algorithm. |
static PublicKey | toJavaKey(SigningPublicKey pk)Convert an I2P SigningPublicKey to a Java PublicKey, dispatching by algorithm. |
static RSAPrivateKey | toJavaRSAKey(SigningPrivateKey pk)Convert an I2P RSA private key to a Java RSAPrivateKey. |
static RSAPublicKey | toJavaRSAKey(SigningPublicKey pk)Prefer toJavaKey(SigningPublicKey) for type-generic conversion. |
static byte[] | toJavaSig(Signature sig)Convert an I2P Signature to a Java ASN.1 signature byte array. |
public static NativeBigInteger[] aSN1ToBigInteger(byte[] asn, int len) throws SignatureException
len - nominal length of each BigIntegerSignatureExceptionpublic static void clearCaches()
static byte[] combine(BigInteger x, BigInteger y, int len) throws InvalidKeyException
x - non-negative first valuey - non-negative second valuelen - total output length (must be even)InvalidKeyException - if length is odd or either value is too largepublic static SigningPrivateKey fromJavaKey(DSAPrivateKey pk) throws GeneralSecurityException
pk - non-nullGeneralSecurityException - if conversion failspublic static SigningPublicKey fromJavaKey(DSAPublicKey pk) throws GeneralSecurityException
pk - non-nullGeneralSecurityException - if conversion failspublic static SigningPrivateKey fromJavaKey(ECPrivateKey pk, SigType type) throws GeneralSecurityException
pk - non-nulltype - the I2P signature typeGeneralSecurityException - if conversion failspublic static SigningPublicKey fromJavaKey(ECPublicKey pk, SigType type) throws GeneralSecurityException
pk - non-nulltype - the I2P signature typeGeneralSecurityException - if conversion failspublic static SigningPrivateKey fromJavaKey(EdDSAPrivateKey pk, SigType type) throws GeneralSecurityException
pk - non-nulltype - the I2P signature typeGeneralSecurityExceptionpublic static SigningPublicKey fromJavaKey(EdDSAPublicKey pk, SigType type)
pk - non-nulltype - the I2P signature typepublic static SigningPrivateKey fromJavaKey(PrivateKey pk) throws GeneralSecurityException
pk - JAVA key!InvalidKeyException - on unknown typeGeneralSecurityExceptionpublic static SigningPrivateKey fromJavaKey(PrivateKey pk, SigType type) throws GeneralSecurityException
pk - JAVA key!GeneralSecurityExceptionpublic static SigningPublicKey fromJavaKey(PublicKey pk) throws GeneralSecurityException
pk - JAVA key!InvalidKeyException - on unknown typeGeneralSecurityExceptionpublic static SigningPublicKey fromJavaKey(PublicKey pk, SigType type) throws GeneralSecurityException
pk - JAVA key!GeneralSecurityExceptionpublic static SigningPrivateKey fromJavaKey(RSAPrivateKey pk, SigType type) throws GeneralSecurityException
pk - non-nulltype - the I2P signature typeGeneralSecurityException - if conversion failspublic static SigningPublicKey fromJavaKey(RSAPublicKey pk, SigType type) throws GeneralSecurityException
pk - non-nulltype - the I2P signature typeGeneralSecurityException - if conversion failspublic static Signature fromJavaSig(byte[] asn, SigType type) throws SignatureException
asn - ASN.1 DER-encoded signature bytes (or raw for RSA/EdDSA)type - the I2P signature typeSignatureException - if ASN.1 decoding failspublic static PrivateKey importJavaPrivateKey(File file, SigType type) throws GeneralSecurityException, IOException
file - non-null, containing PKCS8 encoded key datatype - the I2P signature typeGeneralSecurityException - if key conversion failsIOException - if file reading failspublic static PublicKey importJavaPublicKey(File file, SigType type) throws GeneralSecurityException, IOException
file - non-null, containing X.509 encoded key datatype - the I2P signature typeGeneralSecurityException - if key conversion failsIOException - if file reading failspublic static int intToASN1(byte[] d,
int idx,
int val)val - 0-65535public static byte[] rectify(BigInteger bi, int len) throws InvalidKeyException
bi - non-negativelen - desired output lengthInvalidKeyException - if the value is negative or too large to fitpublic static byte[] sigBytesToASN1(BigInteger r, BigInteger s)
Signature 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 - value
Encode two BigInteger values (r, s) into ASN.1 DER SEQUENCE format.
r 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.r - non-negatives - non-negativeIllegalArgumentException - if too bigpublic static DSAPrivateKey toJavaDSAKey(SigningPrivateKey pk) throws GeneralSecurityException
pk - non-nullGeneralSecurityException - if conversion failspublic static DSAPublicKey toJavaDSAKey(SigningPublicKey pk) throws GeneralSecurityException
pk - non-nullGeneralSecurityException - if conversion failspublic static ECPrivateKey toJavaECKey(SigningPrivateKey pk) throws GeneralSecurityException
pk - non-nullGeneralSecurityException - if conversion failspublic static ECPublicKey toJavaECKey(SigningPublicKey pk) throws GeneralSecurityException
pk - non-nullGeneralSecurityException - if conversion failspublic static EdDSAPrivateKey toJavaEdDSAKey(SigningPrivateKey pk) throws GeneralSecurityException
pk - non-nullGeneralSecurityExceptionpublic static EdDSAPublicKey toJavaEdDSAKey(SigningPublicKey pk) throws GeneralSecurityException
pk - non-nullGeneralSecurityExceptionpublic static PrivateKey toJavaKey(SigningPrivateKey pk) throws GeneralSecurityException
pk - non-nullGeneralSecurityException - if conversion failspublic static PublicKey toJavaKey(SigningPublicKey pk) throws GeneralSecurityException
pk - non-nullGeneralSecurityException - if conversion failspublic static RSAPrivateKey toJavaRSAKey(SigningPrivateKey pk) throws GeneralSecurityException
pk - non-nullGeneralSecurityException - if conversion failspublic static RSAPublicKey toJavaRSAKey(SigningPublicKey pk) throws GeneralSecurityException
pk - non-nullGeneralSecurityException - if conversion failspublic static byte[] toJavaSig(Signature sig)
sig - non-null