crypto
Class CipherEngine

java.lang.Object
  extended by crypto.CipherEngine

public class CipherEngine
extends java.lang.Object

Common ciphering engine (for the whole application) providing: - Asymmetric ciphering: used for signing/verification and encryption/decryption of secret key used in symmetric ciphering. - Symmetric ciphering: used for encryption/decryption of PDUs and secret chat text messages.


Field Summary
private static java.lang.String defaultPrivateKeyDirectory
          Subdirectory of the user.home where private key is stored
private static java.lang.String myCipherAlgorithm
          The default cipher algorithm for data (PDUs and secret chat messages)
private static int myCipherKeySize
          The default key size for cipher algorithm
private static SymmetricCipher myPduCipher
          Symmetric cipher used to encrypt data (PDUs and secret chat messages)
private static java.lang.String myPrivateKeyPath
          Full path of the directory holding our private key
private static AsymmetricCipher privateCipher
          Asymmetric cipher used to encrypt secret keys
 
Constructor Summary
CipherEngine()
           
 
Method Summary
static SymmetricCipher deserializeEncryptedSecretKey(java.lang.String encryptedSecret)
          Reconstructs secret key from Base64 respresentation of encrypted (using our public key) serialized secret key and verifies signature of the remote peer.
static boolean generateNewSecret(java.lang.String algorithm, int keySize, boolean verbose)
          Generates new symmetric secret key.
static SymmetricCipher getCipher()
          Returns local symmetric ciphering engine
static java.lang.String getNamedPublicKey()
          Returns serialized named public key encoded as Base64 string.
static java.lang.String getPrivateKeyDirectory()
          Returns path to the directory holding our private key
static java.lang.String getSignedPublicKey()
          Returns serialized signed public key (used for encryption of datagrams) as Base64 string.
static java.security.SignedObject getSignedSecretKey()
          Returns secret key signed with our private key
static void initialize()
          Loads authorized public keys and initializes asymmetric and symmetric ciphering engines, where: - Asymmetric ciphering is used for verification and encryption/decryption of secret key used in symmetric ciphering
static void reloadAuthorizedPublicKeys()
          Reloads only authorized public keys
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

privateCipher

private static AsymmetricCipher privateCipher
Asymmetric cipher used to encrypt secret keys


myCipherAlgorithm

private static final java.lang.String myCipherAlgorithm
The default cipher algorithm for data (PDUs and secret chat messages)

See Also:
Constant Field Values

myCipherKeySize

private static final int myCipherKeySize
The default key size for cipher algorithm

See Also:
Constant Field Values

defaultPrivateKeyDirectory

private static final java.lang.String defaultPrivateKeyDirectory
Subdirectory of the user.home where private key is stored

See Also:
Constant Field Values

myPrivateKeyPath

private static java.lang.String myPrivateKeyPath
Full path of the directory holding our private key


myPduCipher

private static SymmetricCipher myPduCipher
Symmetric cipher used to encrypt data (PDUs and secret chat messages)

Constructor Detail

CipherEngine

public CipherEngine()
Method Detail

getPrivateKeyDirectory

public static java.lang.String getPrivateKeyDirectory()
Returns path to the directory holding our private key


getSignedPublicKey

public static java.lang.String getSignedPublicKey()
Returns serialized signed public key (used for encryption of datagrams) as Base64 string.


getNamedPublicKey

public static java.lang.String getNamedPublicKey()
Returns serialized named public key encoded as Base64 string.


getCipher

public static SymmetricCipher getCipher()
Returns local symmetric ciphering engine


getSignedSecretKey

public static java.security.SignedObject getSignedSecretKey()
Returns secret key signed with our private key


deserializeEncryptedSecretKey

public static SymmetricCipher deserializeEncryptedSecretKey(java.lang.String encryptedSecret)
Reconstructs secret key from Base64 respresentation of encrypted (using our public key) serialized secret key and verifies signature of the remote peer.


initialize

public static void initialize()
Loads authorized public keys and initializes asymmetric and symmetric ciphering engines, where: - Asymmetric ciphering is used for verification and encryption/decryption of secret key used in symmetric ciphering. - Symmetric ciphering is used for encryption/decryption of PDUs and secret chat text messages. Initialization is non-blocking and performed in separate worker thread.


reloadAuthorizedPublicKeys

public static void reloadAuthorizedPublicKeys()
Reloads only authorized public keys


generateNewSecret

public static boolean generateNewSecret(java.lang.String algorithm,
                                        int keySize,
                                        boolean verbose)
Generates new symmetric secret key.

Returns:
true if generated cipher may be used (i.e. false in case of error)