public class KeyExchange extends Object
CIPHER_PADDING, giving a
Cipher name of CIPHER_NAME.
This class allows you to encrypt a SecretKey so that it can be securely sent to another
user. This is done using the destination user's PublicKey so that the recipient can
decrypt it using their PrivateKey.
Public-private key cryptography is not suitable for bulk encryption of data, (such as text and
documents) so if you need to send encrypted data from one user to another, the process for this
is slightly different, using both public-private and secret key encryption. If you wish to do
this, you need to use something along the lines of the following:
SecretKey, using the Crypto class.SecretKey using the destination user's PublicKey by calling
encryptKey(SecretKey, PublicKey).SecretKey to the destination user with the encrypted data.PrivateKey to decrypt the SecretKey, by calling
decryptKey(String, PrivateKey).SecretKey to decrypt the data, using
the Crypto class.SecretKey so that two parties can use
the same key to encrypt and decrypt data. Another approach is to use "key agreement", but this is
currently beyond the scope of Cryptolite.| Modifier and Type | Field and Description |
|---|---|
static String |
CIPHER_ALGORITHM
The name of the cipher algorithm to use for asymmetric cryptographic operations.
|
static String |
CIPHER_MODE
The name of the cipher mode to use for asymmetric cryptographic operations.
|
static String |
CIPHER_PADDING
The name of the padding type to use for asymmetric cryptographic operations.
|
| Modifier | Constructor and Description |
|---|---|
|
KeyExchange()
Initialises the instance with the recommended setting of .
|
protected |
KeyExchange(String cipherName)
This constructor is protected so that, should you need a different algorithm (e.g.
|
| Modifier and Type | Method and Description |
|---|---|
SecretKey |
decryptKey(String encryptedKey,
PrivateKey privateKey)
This method decrypts the given encrypted
SecretKey using our PrivateKey. |
String |
encryptKey(SecretKey key,
PublicKey destinationPublicKey)
|
public static final String CIPHER_ALGORITHM
public static final String CIPHER_MODE
public static final String CIPHER_PADDING
public KeyExchange()
protected KeyExchange(String cipherName)
cipherName - This should normally be .public String encryptKey(SecretKey key, PublicKey destinationPublicKey)
SecretKey with the destination user's
PublicKey so that it can be safely sent to them.key - The SecretKey to be encrypted.destinationPublicKey - The PublicKey of the user to whom you will be sending the
SecretKey. This can be obtained via Keys.newKeyPair().decryptKey(String, PrivateKey).public SecretKey decryptKey(String encryptedKey, PrivateKey privateKey)
SecretKey using our PrivateKey.encryptedKey - The encrypted key as a base64-encoded string, as returned by
encryptKey(SecretKey, PublicKey).privateKey - The PrivateKey to be used to decrypt the encrypted key. This can be
obtained via Keys.newKeyPair().SecretKey.Copyright © 2016 Carboni. All rights reserved.