Package com.iizix.server.client
Class DHKey
java.lang.Object
com.iizix.server.client.DHKey
Class used to generate a 2048 bits key for password transport over unsecured HTTP transactions.
- Author:
- Christopher Mindus
Constructor Summary
Method Summary
Modifier and TypeMethodDescriptionvoid
assignClientPublicKey
(String publicKey) Assigns the Client's public key.byte[]
Decrypts an encoded string from the client using the two public keys.void
encrypt
(byte[] data, SendTransaction sendTrans) Encrypts and appends the bytes to the SendTransaction.static IvParameterSpec
Gets the IV parameter.Gets the Server's public key.
Constructor Details
DHKey
public DHKey()Constructs the instance creating the server's key only. The client "Alice" public key must be provided later.
Method Details
getIvParameterSpec
Gets the IV parameter.assignClientPublicKey
Assigns the Client's public key.- Parameters:
publicKey
- The "Alice" public key as a hexadecimal number.- Throws:
IllegalArgumentException
- If the public key is invalid.
getServerPublicKey
Gets the Server's public key.- Returns:
- The server's public key as a hexadecimal number.
encrypt
Encrypts and appends the bytes to the SendTransaction.- Parameters:
data
- The data to encrypt.sendTrans
- The send transaction.- Throws:
Exception
- For errors.
decrypt
public byte[] decrypt(String clientPublicKey, String encryptedString) throws InvalidKeyException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException Decrypts an encoded string from the client using the two public keys.- Parameters:
clientPublicKey
- The client public key.encryptedString
- The encrypted string encoded as a Base 64 string.- Returns:
- The decrypted string.
- Throws:
InvalidAlgorithmParameterException
InvalidKeyException
NoSuchPaddingException
NoSuchAlgorithmException
BadPaddingException
IllegalBlockSizeException
UnsupportedEncodingException