public class PrivateKeyFile extends Object
- Destination (387 bytes if no certificate, otherwise longer)
- Public key (256 bytes), random data as of 0.9.57 (except for RouterPrivateKeyFile)
- Signing Public key (128 bytes)
- Cert. type (1 byte)
- Cert. length (2 bytes)
- Certificate if length != 0
- Private key (256 bytes for ElGamal, or length specified by key certificate)
- All zeros as of 0.9.57 (except for RouterPrivateKeyFile)
- Signing Private key (20 bytes, or length specified by key certificate)
- As of 0.9.38, if the Signing Private Key is all zeros,
the offline signature section (see proposal 123):
- Expires timestamp (4 bytes, seconds since epoch, rolls over in 2106)
- Sig type of transient public key (2 bytes)
- Transient Signing Public key (length as specified by transient sig type)
- Signature of Signed Public key by offline key (length as specified by destination sig type)
- Transient Signing Private key (length as specified by transient sig type)
Total: 663 or more bytes for ElGamal, may be smaller for other enc. types
Destination encryption keys have been unused since 0.6 (2005).
As of 0.9.57, new Destination encryption public keys are simply random data,
and encryption private keys may be random data or all zeros.
This class is extended by net.i2p.data.router.RouterPrivateKeyFile.
RouterIdentity encryption keys ARE used and must be valid.| Modifier and Type | Field and Description |
|---|---|
protected Destination | destthe destination |
protected File | filethe key file |
protected PrivateKey | privKeythe private key |
protected SigningPrivateKey | signingPrivKeythe signing private key |
| Constructor and Description |
|---|
PrivateKeyFile(File file)Create a new PrivateKeyFile from a File. |
PrivateKeyFile(File file,
Destination dest,
PrivateKey pk,
SigningPrivateKey spk)Create a new PrivateKeyFile with a destination and keys. |
PrivateKeyFile(File file,
I2PClient client)Create a new PrivateKeyFile with a client. |
PrivateKeyFile(File file,
I2PSession session)Create a new PrivateKeyFile from an I2P session. |
PrivateKeyFile(File file,
PublicKey pubkey,
SigningPublicKey spubkey,
Certificate cert,
PrivateKey pk,
SigningPrivateKey spk)Create a new PrivateKeyFile from individual key components. |
PrivateKeyFile(File file,
PublicKey pubkey,
SigningPublicKey spubkey,
Certificate cert,
PrivateKey pk,
SigningPrivateKey spk,
byte[] padding)Create a new PrivateKeyFile from individual key components with padding. |
PrivateKeyFile(InputStream in)Read a PrivateKeyFile from an input stream. |
PrivateKeyFile(String file)Create a new PrivateKeyFile from a file name. |
| Modifier and Type | Method and Description |
|---|---|
static boolean | checkSignature(Signature s,
byte[] data,
SigningPublicKey spk)Check a signature against data with a public key. |
Destination | createIfAbsent()Create with the default signature type if nonexistent. |
Destination | createIfAbsent(SigType type)Create with the specified signature type if nonexistent. |
Destination | getDestination()If the destination is not set, read it in from the file. |
long | getOfflineExpiration()Get the offline key expiration time. |
Signature | getOfflineSignature()Get the offline signature. |
PrivateKey | getPrivKey()Private key may be random data or all zeros for Destinations as of 0.9.57 |
SigningPrivateKey | getSigningPrivKey()Get the signing private key. |
SigningPrivateKey | getTransientSigningPrivKey()Get the transient signing private key. |
SigningPublicKey | getTransientSigningPubKey()Get the transient signing public key. |
boolean | isOffline()Does this session have offline and transient keys? |
static void | main(String[] args)Create a new PrivateKeyFile, or modify an existing one, with various
types of Certificates. |
I2PSession | open()Open an I2P session. |
I2PSession | open(Properties opts)Open a session with the given options. |
Certificate | setCertType(int t)Change cert type - caller must also call write(). |
void | setDestination(Destination d)Set the destination. |
Certificate | setKeyCert(SigType type)Change cert type - caller must also call write(). |
void | setOfflineData(long expires,
SigningPublicKey transientPub,
Signature sig,
SigningPrivateKey transientPriv)Side effect - zeroes out the current signing private key |
Certificate | setSignedCert(PrivateKeyFile pkf2)Sign this dest by dest found in pkf2 - caller must also call write(). |
String | toString() |
boolean | validateKeyPairs()Verify that the PublicKey matches the PrivateKey, and
the SigningPublicKey matches the SigningPrivateKey. |
static boolean | verifySignature(Destination d)Verify the signature on a destination. |
void | write()Write the keys to the file. |
protected Destination dest
protected final File file
protected PrivateKey privKey
protected SigningPrivateKey signingPrivKey
public PrivateKeyFile(File file)
file - the key filepublic PrivateKeyFile(File file, Destination dest, PrivateKey pk, SigningPrivateKey spk)
file - the key filedest - the destinationpk - the private keyspk - the signing private keyIllegalArgumentException - on mismatch of spubkey and spk typespublic PrivateKeyFile(File file, I2PClient client)
file - the key fileclient - the I2P clientpublic PrivateKeyFile(File file, I2PSession session)
file - the key filesession - the I2P sessionpublic PrivateKeyFile(File file, PublicKey pubkey, SigningPublicKey spubkey, Certificate cert, PrivateKey pk, SigningPrivateKey spk)
file - the key filepubkey - the public keyspubkey - the signing public keycert - the certificatepk - the private keyspk - the signing private keyIllegalArgumentException - on mismatch of spubkey and spk typespublic PrivateKeyFile(File file, PublicKey pubkey, SigningPublicKey spubkey, Certificate cert, PrivateKey pk, SigningPrivateKey spk, byte[] padding)
file - the key filepubkey - the public keyspubkey - the signing public keycert - the certificatepk - the private keyspk - the signing private keypadding - null OK, must be non-null if spubkey length < 128IllegalArgumentException - on mismatch of spubkey and spk typespublic PrivateKeyFile(InputStream in) throws I2PSessionException
in - the input streamI2PSessionException - if session creation failspublic PrivateKeyFile(String file)
file - the key file namepublic static boolean checkSignature(Signature s, byte[] data, SigningPublicKey spk)
s - the signature to verifydata - the data that was signedspk - the signing public keypublic Destination createIfAbsent() throws I2PException, IOException
I2PException - if creation failsIOException - if file operations failpublic Destination createIfAbsent(SigType type) throws I2PException, IOException
type - the signature type to useI2PException - if creation failsIOException - if file operations failpublic Destination getDestination() throws I2PSessionException, IOException, DataFormatException
I2PSessionException - if reading failsIOException - if file operations failDataFormatException - if data is malformedpublic long getOfflineExpiration()
public Signature getOfflineSignature()
public PrivateKey getPrivKey()
public SigningPrivateKey getSigningPrivKey()
public SigningPrivateKey getTransientSigningPrivKey()
public SigningPublicKey getTransientSigningPubKey()
public boolean isOffline()
public static void main(String[] args)
args - command line argumentspublic I2PSession open() throws I2PSessionException, IOException
I2PSessionException - if session creation failsIOException - if there is an error reading the key filepublic I2PSession open(Properties opts) throws I2PSessionException, IOException
opts - the options for the sessionI2PSessionException - if session creation failsIOException - if there is an error reading the key filepublic Certificate setCertType(int t)
t - the certificate typepublic void setDestination(Destination d)
d - the destinationpublic Certificate setKeyCert(SigType type)
type - the signature typepublic void setOfflineData(long expires,
SigningPublicKey transientPub,
Signature sig,
SigningPrivateKey transientPriv)expires - expiration time in Java mstransientPub - the transient signing public keysig - the offline signaturetransientPriv - the transient signing private keypublic Certificate setSignedCert(PrivateKeyFile pkf2)
pkf2 - the signing key filepublic boolean validateKeyPairs()
public static boolean verifySignature(Destination d)
d - the destination to verifypublic void write()
throws IOException,
DataFormatExceptionIOException - if file operations failDataFormatException - if data encoding fails