java.lang.Object
net.i2p.data.SimpleDataStructure
net.i2p.data.SigningPrivateKey
- All Implemented Interfaces:
Destroyable, DataStructure
- Direct Known Subclasses:
RSASigningPrivateCrtKey
Cryptographic private key for digital signature generation in I2P.
SigningPrivateKey provides signature generation capabilities:
- Default Algorithm: DSA-SHA1 (20 bytes)
- Modern Support: Variable length and type support since 0.9.8
- Key Structure: Contains only private exponent/coordinates
- Security: Implements
Destroyablefor secure cleanup
Supported Algorithms:
- DSA-SHA1: Legacy algorithm, 20-byte keys
- ECDSA-P256: Modern algorithm, variable length keys
- EdDSA-Ed25519: Modern algorithm, 32-byte keys
- Future Types: Extensible design for new algorithms
Key Format:
- DSA: 20-byte private exponent (x)
- ECDSA: Variable length private scalar
- EdDSA: 32-byte private seed
- Type Encoding: Algorithm type embedded in data
Usage:
- Signature Generation: Sign data with corresponding
SigningPublicKey - Identity Creation: Part of
Destinationidentity - LeaseSet Signing: Sign LeaseSet for network publication
- Router Identity: Sign router information for NetDb
Security Considerations:
- Confidentiality: Private signing keys must never be exposed
- Secure Destruction: Call
destroy()when no longer needed - Memory Protection: Zeroize memory after use
- Algorithm Choice: Prefer modern algorithms (Ed25519, ECDSA-P256)
Blinding Support:
- Key Blinding: Support for generating blinded key variants
- Privacy: Enable anonymous service endpoints
- BlindData: Integration with
BlindDatafor blinding operations
Performance Features:
- Efficient Storage: Optimized byte representation
- Factory Methods: Static creation methods for consistency
- Fast Operations: Optimized for high-frequency signing
Migration Path:
- Legacy: DSA-SHA1 for backward compatibility
- Modern: Ed25519 for better performance and security
- Transition: Mixed algorithm support during migration
Thread Safety:
- Immutable Data: Key data cannot be modified after creation
- Safe Destruction: Thread-safe key zeroization
- Exclusive Use: Each instance should be used by only one thread
Field Summary
Fields inherited from class SimpleDataStructure
_dataConstructor Summary
ConstructorsConstructorDescriptionCreates a new SigningPrivateKey with the default DSA-SHA1 type.SigningPrivateKey(byte[] data) Creates a new SigningPrivateKey from byte data with default type.SigningPrivateKey(String base64Data) Signing private key from a string of base64 data.SigningPrivateKey(SigType type) Creates an empty signing private key for the given signature algorithm.SigningPrivateKey(SigType type, byte[] data) Creates a signing private key for the given algorithm from raw key bytes.Method Summary
All MethodsModifier and TypeMethodDescriptionblind(SigningPrivateKey alpha) Only for SigType EdDSA_SHA512_Ed25519.voiddestroy()Destroy this key and clear its data, per the javax.security.auth.Destroyable interface.booleanEqual if the keys are equal.getType()Signature type of this private key.inthashCode()Hash code combining the type and data.booleanWhether this key has been destroyed.booleanConstant time.intlength()Key length in bytes, determined by the signature type.toPublic()Converts this signing private key to its public equivalent.toString()Key summary for log messages.Methods inherited from class SimpleDataStructure
calculateHash, fromBase64, fromByteArray, getData, read, readBytes, setData, toBase64, toByteArray, writeBytesModifier and TypeMethodDescriptionSHA256 hash of the byte array, or null if data is null.voidfromBase64(String data) Data from the base64 string.voidfromByteArray(byte[] data) Does the same thing asSimpleDataStructure.setData(byte[])but null not allowed.byte[]getData()Data reference (not a copy).protected intread(InputStream in, byte[] target) Repeated reads until the buffer is full or IOException is thrown.voidreadBytes(InputStream in) Data read from the stream.voidsetData(byte[] data) The byte array data, or null.toBase64()Renders the structure into modified base 64 notation.byte[]Same thing as getData().voidwriteBytes(OutputStream out) Writes the data to the output stream.
Field Details
DEF_TYPE
Type assumed when a key gives none.KEYSIZE_BYTES
public static final int KEYSIZE_BYTESDefault key size in bytes (20 for DSA-SHA1)._type
The algorithm this key signs with.
Constructor Details
SigningPrivateKey
public SigningPrivateKey()Creates a new SigningPrivateKey with the default DSA-SHA1 type.SigningPrivateKey
Creates an empty signing private key for the given signature algorithm.- Parameters:
type- the signature algorithm this key is used with, which fixes the key length
SigningPrivateKey
public SigningPrivateKey(byte[] data) Creates a new SigningPrivateKey from byte data with default type.- Parameters:
data- the raw private key bytes, which must match the default type's key length
SigningPrivateKey
Creates a signing private key for the given algorithm from raw key bytes.- Parameters:
type- the signature algorithm, which fixes the key length and signing algorithmdata- the raw private key bytes, whose length must match the type's privkey length
SigningPrivateKey
Signing private key from a string of base64 data.- Parameters:
base64Data- a string of base64 data (the output of .toBase64() called on a prior instance of SigningPrivateKey- Throws:
DataFormatException- if the string is not valid base64, or does not decode to the key length required by the default signature type
Method Details
length
public int length()Key length in bytes, determined by the signature type.- Specified by:
lengthin classSimpleDataStructure- Returns:
- the legal length of the byte array
getType
toPublic
Converts this signing private key to its public equivalent. As of 0.9.16, supports all key types.- Returns:
- a SigningPublicKey object derived from this private key
- Throws:
IllegalArgumentException- on bad key or unknown or unsupported type
blind
Only for SigType EdDSA_SHA512_Ed25519.- Parameters:
alpha- the secret data- Returns:
- the blinded private key
- Throws:
UnsupportedOperationException- never thrown; see IllegalArgumentException
isOffline
public boolean isOffline()Constant time.- Returns:
- true if all zeros
destroy
public void destroy()Destroy this key and clear its data, per the javax.security.auth.Destroyable interface.- Specified by:
destroyin interfaceDestroyable
isDestroyed
public boolean isDestroyed()Whether this key has been destroyed.- Specified by:
isDestroyedin interfaceDestroyable- Returns:
- true if
destroy()has cleared the key data, or it was never set
toString
Key summary for log messages.- Overrides:
toStringin classSimpleDataStructure
hashCode
public int hashCode()Hash code combining the type and data.- Overrides:
hashCodein classSimpleDataStructure- Returns:
- the hash code
equals
Equal if the keys are equal.- Overrides:
equalsin classSimpleDataStructure- Parameters:
obj- the object to compare- Returns:
- true if the data arrays are equal