Package org.openmuc.jdlms
Class SecurityUtils
- java.lang.Object
-
- org.openmuc.jdlms.SecurityUtils
-
public class SecurityUtils extends java.lang.Object
A static utility class that provides security functions.This class is useful if you may want to change the security setup of the remote meter.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
SecurityUtils.KeyId
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]
cipherWithAes128(byte[] masterKey, byte[] iv, byte[] bytesToCipher)
Encrypts a byte array with a master key with the algorithm AES in mode CBC and no padding.static byte[]
generateAES128Key()
Generates a random AES 128 keystatic byte[]
generateAES256Key()
Generates a random AES 256 keystatic MethodParameter
keyChangeMethodParamFor(byte[] masterKey, byte[] newKey, SecurityUtils.KeyId keyId)
Returns the method parameter for updating a single key of a DLMS server.static MethodParameter
securityActivateMethodParamFor(SecuritySuite.SecurityPolicy securityPolicy)
Sets the security policy method parameterstatic byte[]
unwrapAesRFC3394Key(byte[] kek, byte[] wrappedKey)
This function unwraps a wrapped key with the kek (key encryption key)static byte[]
wrapAesRFC3394Key(byte[] kek, byte[] key)
This function wraps a key with a kek (key encryption key)
-
-
-
Method Detail
-
keyChangeMethodParamFor
public static MethodParameter keyChangeMethodParamFor(byte[] masterKey, byte[] newKey, SecurityUtils.KeyId keyId)
Returns the method parameter for updating a single key of a DLMS server.- Parameters:
masterKey
- the master key, also known as KEKnewKey
- the new key to update to the DLMS serverkeyId
- the type of key to update- Returns:
- return MethodParameter for global key transfer
-
securityActivateMethodParamFor
public static MethodParameter securityActivateMethodParamFor(SecuritySuite.SecurityPolicy securityPolicy)
Sets the security policy method parameter- Parameters:
securityPolicy
- the security policy to set for- Returns:
- return MethodParameter for security policy
-
cipherWithAes128
public static byte[] cipherWithAes128(byte[] masterKey, byte[] iv, byte[] bytesToCipher) throws java.security.GeneralSecurityException
Encrypts a byte array with a master key with the algorithm AES in mode CBC and no padding.- Parameters:
masterKey
- the master key for encryption the bytesToCypher.iv
- the initialization vector.bytesToCipher
- the bytes to cipher.- Returns:
- the bytesToCipher encrypted
- Throws:
java.security.GeneralSecurityException
- caused byCipher.doFinal(byte[])
orCipher.init(int, Key)
-
wrapAesRFC3394Key
public static byte[] wrapAesRFC3394Key(byte[] kek, byte[] key)
This function wraps a key with a kek (key encryption key)- Parameters:
kek
- the key encryption key for wrapping the keykey
- the key to wrap- Returns:
- returns a with kek wrapped key
-
unwrapAesRFC3394Key
public static byte[] unwrapAesRFC3394Key(byte[] kek, byte[] wrappedKey) throws org.bouncycastle.crypto.InvalidCipherTextException
This function unwraps a wrapped key with the kek (key encryption key)- Parameters:
kek
- the key encryption key for unwrapping the wrapped keywrappedKey
- the wrapped key to unwrap- Returns:
- returns a unwrapped key
- Throws:
org.bouncycastle.crypto.InvalidCipherTextException
- will thrown if something unexpected is in the wrappedKey
-
generateAES128Key
public static byte[] generateAES128Key()
Generates a random AES 128 key- Returns:
- returns a random AES 128 key
-
generateAES256Key
public static byte[] generateAES256Key()
Generates a random AES 256 key- Returns:
- returns a random AES 128 key
-
-