Class EncryptionContext

java.lang.Object
org.netxms.base.EncryptionContext

public final class EncryptionContext extends Object
Encryption context for NXCP communication session
  • Constructor Details

    • EncryptionContext

      protected EncryptionContext(int cipher, NXCPMessage request) throws GeneralSecurityException
      Internal constructor
      Parameters:
      cipher - cipher to use
      request - NXCP message with key exchange request
      Throws:
      GeneralSecurityException - if any of underlying crypto functions fails
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
      See Also:
    • getCipherName

      public static String getCipherName(int cipher)
      Get cipher name
      Parameters:
      cipher - cipher ID
      Returns:
      cipher name or null if ID is invalid or cipher is not supported
    • testCipher

      public static boolean testCipher(int cipherId)
      Test cipher with given ID
      Parameters:
      cipherId - cipher ID
      Returns:
      true if cipher is available and working correctly
    • createInstance

      public static EncryptionContext createInstance(NXCPMessage request) throws NXCPException
      Create encryption context based on information from session key request message.
      Parameters:
      request - session key request message
      Returns:
      encryption context
      Throws:
      NXCPException - if encryption context cannot be created
    • getEncryptedSessionKey

      public byte[] getEncryptedSessionKey() throws GeneralSecurityException
      Encrypt session key with public key from encryption setup message.
      Returns:
      encrypted session key
      Throws:
      GeneralSecurityException - if any of underlying crypto functions fail
    • getEncryptedIv

      public byte[] getEncryptedIv() throws GeneralSecurityException
      Encrypt initialization vector with public key from encryption setup message.
      Returns:
      encrypted initialization vector
      Throws:
      GeneralSecurityException - if any of underlying crypto functions fail
    • encryptMessage

      public byte[] encryptMessage(NXCPMessage msg, boolean allowCompression) throws IOException, GeneralSecurityException
      Encrypt NXCP message.
      Parameters:
      msg - message to encrypt
      allowCompression - true if payload compression is allowed
      Returns:
      encrypted message as sequence of bytes, ready to send over the network
      Throws:
      IOException - if I/O error occurs
      GeneralSecurityException - if any of underlying crypto functions fails
      InvalidKeyException - if encryption key is invalid
    • decryptMessage

      public byte[] decryptMessage(NXCPDataInputStream inputStream, int length) throws GeneralSecurityException, IOException
      Decrypt message from input stream
      Parameters:
      inputStream - input stream
      length - length of encrypted message
      Returns:
      decrypted message
      Throws:
      GeneralSecurityException - if any of underlying crypto functions fails
      IOException - if I/O error occurs
    • getCipher

      public int getCipher()
      Get cipher
      Returns:
      cipher
    • getKeyLength

      public int getKeyLength()
      Get key length (in bytes)
      Returns:
      key length (in bytes)
    • getIvLength

      public int getIvLength()
      Get initialization vector length (in bytes)
      Returns:
      initialization vector length (in bytes)
    • getServerKeyFingerprint

      public String getServerKeyFingerprint()
      Get fingerprint of server public key
      Returns:
      fingerprint of server public key