Class DHKey


  • public class DHKey
    extends java.lang.Object
    Class used to generate a 2048 bits key for password transport over unsecured HTTP transactions.
    Author:
    Christopher Mindus
    • Constructor Summary

      Constructors 
      Constructor Description
      DHKey()
      Constructs the instance creating the server's key only.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void assignClientPublicKey​(java.lang.String publicKey)
      Assigns the Client's public key.
      byte[] decrypt​(java.lang.String clientPublicKey, java.lang.String encryptedString)
      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 javax.crypto.spec.IvParameterSpec getIvParameterSpec()
      Gets the IV parameter.
      java.lang.String getServerPublicKey()
      Gets the Server's public key.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DHKey

        public DHKey()
        Constructs the instance creating the server's key only. The client "Alice" public key must be provided later.
    • Method Detail

      • getIvParameterSpec

        public static javax.crypto.spec.IvParameterSpec getIvParameterSpec()
        Gets the IV parameter.
      • assignClientPublicKey

        public void assignClientPublicKey​(java.lang.String publicKey)
        Assigns the Client's public key.
        Parameters:
        publicKey - The "Alice" public key as a hexadecimal number.
        Throws:
        java.lang.IllegalArgumentException - If the public key is invalid.
      • getServerPublicKey

        public java.lang.String getServerPublicKey()
        Gets the Server's public key.
        Returns:
        The server's public key as a hexadecimal number.
      • encrypt

        public void encrypt​(byte[] data,
                            SendTransaction sendTrans)
                     throws java.lang.Exception
        Encrypts and appends the bytes to the SendTransaction.
        Parameters:
        data - The data to encrypt.
        sendTrans - The send transaction.
        Throws:
        java.lang.Exception - For errors.
      • decrypt

        public byte[] decrypt​(java.lang.String clientPublicKey,
                              java.lang.String encryptedString)
                       throws java.security.InvalidKeyException,
                              java.security.InvalidAlgorithmParameterException,
                              java.security.NoSuchAlgorithmException,
                              javax.crypto.NoSuchPaddingException,
                              javax.crypto.IllegalBlockSizeException,
                              javax.crypto.BadPaddingException,
                              java.io.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:
        java.security.InvalidAlgorithmParameterException
        java.security.InvalidKeyException
        javax.crypto.NoSuchPaddingException
        java.security.NoSuchAlgorithmException
        javax.crypto.BadPaddingException
        javax.crypto.IllegalBlockSizeException
        java.io.UnsupportedEncodingException