Class DHSession


  • public class DHSession
    extends java.lang.Object
    This class represents a Diffie-Hellman (DH) session. After the DH key agreement has been completed, the resulting session key can be used for (symmetric) encryption/ decryption.
    Author:
    radicke, tzangerl
    • Constructor Summary

      Constructors 
      Constructor Description
      DHSession​(boolean isServer, int sessionIVLen)
      Construct new Diffie-Hellman key exchange session
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] decrypt​(java.lang.String cipherSpec, java.lang.String keySpec, int blocksize, byte[] encrypted)  
      byte[] encrypt​(java.lang.String cipherSpec, java.lang.String keySpec, int blocksize, byte[] unencrypted)  
      void finaliseKeyAgreement​(java.lang.String dhmessage)  
      java.lang.String getEncodedDHMaterial()  
      void setPaddedKey​(boolean paddedKey)  
      void setSessionIVLen​(int len)  
      • Methods inherited from class java.lang.Object

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

      • DHSession

        public DHSession​(boolean isServer,
                         int sessionIVLen)
                  throws java.security.InvalidAlgorithmParameterException,
                         java.security.NoSuchAlgorithmException,
                         java.security.InvalidKeyException,
                         java.security.NoSuchProviderException
        Construct new Diffie-Hellman key exchange session
        Throws:
        java.security.InvalidAlgorithmParameterException - Invalid DH parameters (primes)
        java.security.NoSuchAlgorithmException - DH algorithm not available in VM
        java.security.InvalidKeyException - Private key generated by DH generator invalid
        java.security.NoSuchProviderException - Bouncy castle provider does not exist
    • Method Detail

      • getEncodedDHMaterial

        public java.lang.String getEncodedDHMaterial()
                                              throws java.io.IOException
        Throws:
        java.io.IOException
      • finaliseKeyAgreement

        public void finaliseKeyAgreement​(java.lang.String dhmessage)
                                  throws java.io.IOException,
                                         java.security.GeneralSecurityException,
                                         java.lang.IllegalStateException
        Throws:
        java.io.IOException
        java.security.GeneralSecurityException
        java.lang.IllegalStateException
      • decrypt

        public byte[] decrypt​(java.lang.String cipherSpec,
                              java.lang.String keySpec,
                              int blocksize,
                              byte[] encrypted)
                       throws java.security.InvalidKeyException,
                              java.lang.IllegalStateException,
                              java.security.NoSuchAlgorithmException,
                              javax.crypto.NoSuchPaddingException,
                              javax.crypto.IllegalBlockSizeException,
                              javax.crypto.BadPaddingException,
                              java.security.InvalidAlgorithmParameterException,
                              java.security.NoSuchProviderException
        Throws:
        java.security.InvalidKeyException
        java.lang.IllegalStateException
        java.security.NoSuchAlgorithmException
        javax.crypto.NoSuchPaddingException
        javax.crypto.IllegalBlockSizeException
        javax.crypto.BadPaddingException
        java.security.InvalidAlgorithmParameterException
        java.security.NoSuchProviderException
      • setPaddedKey

        public void setPaddedKey​(boolean paddedKey)
      • setSessionIVLen

        public void setSessionIVLen​(int len)
      • encrypt

        public byte[] encrypt​(java.lang.String cipherSpec,
                              java.lang.String keySpec,
                              int blocksize,
                              byte[] unencrypted)
                       throws java.security.InvalidKeyException,
                              java.lang.IllegalStateException,
                              java.security.NoSuchAlgorithmException,
                              javax.crypto.NoSuchPaddingException,
                              javax.crypto.IllegalBlockSizeException,
                              javax.crypto.BadPaddingException,
                              java.security.InvalidAlgorithmParameterException,
                              java.security.NoSuchProviderException
        Throws:
        java.security.InvalidKeyException
        java.lang.IllegalStateException
        java.security.NoSuchAlgorithmException
        javax.crypto.NoSuchPaddingException
        javax.crypto.IllegalBlockSizeException
        javax.crypto.BadPaddingException
        java.security.InvalidAlgorithmParameterException
        java.security.NoSuchProviderException