Package org.netxms.base
Class EncryptionContext
java.lang.Object
org.netxms.base.EncryptionContext
Encryption context for NXCP communication session
-
Constructor Summary
ModifierConstructorDescriptionprotected
EncryptionContext
(int cipher, NXCPMessage request) Internal constructor -
Method Summary
Modifier and TypeMethodDescriptionstatic EncryptionContext
createInstance
(NXCPMessage request) Create encryption context based on information from session key request message.byte[]
decryptMessage
(NXCPDataInputStream inputStream, int length) Decrypt message from input streambyte[]
encryptMessage
(NXCPMessage msg, boolean allowCompression) Encrypt NXCP message.int
Get cipherstatic String
getCipherName
(int cipher) Get cipher namebyte[]
Encrypt initialization vector with public key from encryption setup message.byte[]
Encrypt session key with public key from encryption setup message.int
Get initialization vector length (in bytes)int
Get key length (in bytes)Get fingerprint of server public keystatic boolean
testCipher
(int cipherId) Test cipher with given IDtoString()
-
Constructor Details
-
EncryptionContext
Internal constructor- Parameters:
cipher
- cipher to userequest
- NXCP message with key exchange request- Throws:
GeneralSecurityException
- if any of underlying crypto functions fails
-
-
Method Details
-
toString
-
getCipherName
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
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
Encrypt session key with public key from encryption setup message.- Returns:
- encrypted session key
- Throws:
GeneralSecurityException
- if any of underlying crypto functions fail
-
getEncryptedIv
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 encryptallowCompression
- 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 occursGeneralSecurityException
- if any of underlying crypto functions failsInvalidKeyException
- if encryption key is invalid
-
decryptMessage
public byte[] decryptMessage(NXCPDataInputStream inputStream, int length) throws GeneralSecurityException, IOException Decrypt message from input stream- Parameters:
inputStream
- input streamlength
- length of encrypted message- Returns:
- decrypted message
- Throws:
GeneralSecurityException
- if any of underlying crypto functions failsIOException
- 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
Get fingerprint of server public key- Returns:
- fingerprint of server public key
-