|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcrypto.AsymmetricCipher
public class AsymmetricCipher
Implements asymmetric cipher with public and private keys used to retrieve secret key (used for symmetric ciphering of peer-to-peer datagram packets) from remote peer. Remote peer sends its secret key encrypted with our public key. Transmission of the SecretKey can be schematically shown:
Send secret key: secretKey >> serialize >> encrypt (with PubKey) >> encode to Base64 >> transmit Reconstruct secret key: receive >> decode from Base64 >> decrypt (with PrivKey) >> deserialize >> secretKey
Field Summary | |
---|---|
private static java.lang.String |
algorithm
Asymmetric cipher algorithm |
private javax.crypto.Cipher |
cipher
Instance of the decrypting engine based on our private key |
private static java.lang.String |
digest
Message digest used for creating/validating signatures |
private java.lang.String |
keyPairComment
The comment (description) of the key pair |
private static int |
keySize
Default key size for algorithm |
private static java.lang.String |
padding
Padding to be used when ciphering/deciphering. |
private java.security.PrivateKey |
privateKey
Private key used for deciphering and signing messages |
private static java.lang.String |
privateKeyFile
The name of the file holding saved private key |
private java.security.PublicKey |
publicKey
Public key corresponding to our private key |
private static java.lang.String |
publicKeyFile
The name of the file holding saved public key |
private java.lang.String |
serializedPublicKey
Our public key: serialized and encoded as Base64 string. |
Constructor Summary | |
---|---|
AsymmetricCipher()
Generates a pair of keys and serializes public key as Base64 string. |
Method Summary | |
---|---|
byte[] |
decrypt(byte[] cipherText)
Decrypts cipher text using the private key. |
SymmetricCipher |
deserializeEncryptedSecretKey(java.lang.String serializedSecretKey)
Reconstructs secret key from Base64 respresentation of encrypted (using our public key) serialized secret key. |
private void |
destruct()
Destructs object (makes it inactive) |
void |
exportPublicKey(java.lang.String fileName)
Save public key into file |
private void |
generateKeyPair()
Generates a key pair |
java.lang.String |
getNamedPublicKey()
Returns serializable named publicKey (with comment) encoded as Base64 |
java.lang.String |
getSerializedAndSignedPublicKey()
Returns serialized public key used for encryption of datagrams as Base64 string. |
private void |
instantiateCipher()
Instantiates a cipher |
boolean |
isActive()
Returns if cipher is properly initialized |
static java.lang.Object |
loadObject(java.lang.String fileName)
Loads serializable object encoded in Base64 from file |
private boolean |
loadSavedKeyPair()
Load saved key pair |
private boolean |
sanityCheck()
Sanity check whether PublicEncryptor works with PrivateEncryption |
private void |
saveKeyPair()
Saves private/public key pair with description (this.keyPairComment) |
static boolean |
saveObject(java.io.Serializable object,
java.lang.String fileName,
java.lang.String comment)
Saves serializable object encoded in Base64 to file |
private void |
serializePublicKey()
Serializes the public key, signs it and encodes in Base64 format |
java.security.SignedObject |
signObject(java.io.Serializable object)
Signs object using private key |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String algorithm
private static final int keySize
private static final java.lang.String padding
private static final java.lang.String digest
private static final java.lang.String privateKeyFile
private static final java.lang.String publicKeyFile
private java.security.PrivateKey privateKey
private java.security.PublicKey publicKey
private java.lang.String keyPairComment
private javax.crypto.Cipher cipher
private java.lang.String serializedPublicKey
Constructor Detail |
---|
public AsymmetricCipher()
Method Detail |
---|
private void destruct()
private boolean loadSavedKeyPair()
private void saveKeyPair()
private void generateKeyPair()
private void instantiateCipher()
private void serializePublicKey()
public boolean isActive()
public java.lang.String getSerializedAndSignedPublicKey()
public void exportPublicKey(java.lang.String fileName)
fileName
- file where to save public key; if null, it will be
the default: AssymmetricCipher.publicKeyFilepublic java.lang.String getNamedPublicKey()
public static boolean saveObject(java.io.Serializable object, java.lang.String fileName, java.lang.String comment)
public static java.lang.Object loadObject(java.lang.String fileName)
private boolean sanityCheck()
public byte[] decrypt(byte[] cipherText)
PublicEncryptor.encrypt(byte[])
public java.security.SignedObject signObject(java.io.Serializable object)
public SymmetricCipher deserializeEncryptedSecretKey(java.lang.String serializedSecretKey)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |