Class BlockCipherSerializer
java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.serializer.Serializer
services.moleculer.serializer.ChainedSerializer
services.moleculer.serializer.BlockCipherSerializer
- All Implemented Interfaces:
MoleculerLifecycle
Serializer with Symmetric Key Encryption. This enables message-level
encryption. Sample of usage:
BlockCipherSerializer serializer = new BlockCipherSerializer();
serializer.setAlgorithm("AES/CBC/PKCS5Padding");
serializer.setPassword("12345678901234567890123456789012");
serializer.setIv("1234567890123456");
Transporter trans = new NatsTransporter("localhost");
trans.setSerializer(serializer);
ServiceBroker broker = ServiceBroker.builder()
.nodeID("node1")
.transporter(trans)
.build();
Chaining Serializers (serialize then compress then encrypt packets):
Transporter trans = new NatsTransporter("localhost");
MsgPackSerializer msgPack = new MsgPackSerializer();
DeflaterSerializer deflater = new DeflaterSerializer(msgPack);
BlockCipherSerializer cipher = new BlockCipherSerializer(deflater);
trans.setSerializer(cipher);
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringType of the block Cipher.protected ThreadLocal<Cipher> static final StringSame as "aes-256-cbc" in Node.js.static final byte[]Empty IV block.protected ThreadLocal<Cipher> protected byte[]Algorithm parameters (IV).protected StringPassword for Symmetric Key Encryption.protected SecretKeySpecSecretKeySpec, can be specified externally.Fields inherited from class ChainedSerializer
parentFields inherited from class Serializer
debug, format, reader, writerFields inherited from class MoleculerComponent
broker, logger, name -
Constructor Summary
ConstructorsConstructorDescriptionCreates a JSON Serializer that uses AES encryption algorithm with the default password (using the hard-coded, default password is not very secure).BlockCipherSerializer(String password) Creates a JSON Serializer that uses AES encryption algorithm to encrypt/decrypt messages.BlockCipherSerializer(String password, String algorithm, byte[] iv) Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.BlockCipherSerializer(String password, String algorithm, String iv) Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.BlockCipherSerializer(Serializer parent) Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.BlockCipherSerializer(Serializer parent, String password) Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.BlockCipherSerializer(Serializer parent, String password, String algorithm) Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.BlockCipherSerializer(Serializer parent, String password, String algorithm, byte[] iv) Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.BlockCipherSerializer(Serializer parent, String password, String algorithm, String iv) Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages. -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]protected byte[]protected Stringprotected Cipherprotected Cipherbyte[]getIv()io.datatree.Treeread(byte[] source) voidsetAlgorithm(String algorithm) voidsetIv(byte[] iv) voidvoidsetPassword(String password) voidsetSecretKey(SecretKeySpec secretKey) voidstarted(ServiceBroker broker) byte[]write(io.datatree.Tree value) Methods inherited from class ChainedSerializer
getFormat, setDebug, stoppedMethods inherited from class Serializer
isDebugMethods inherited from class MoleculerComponent
getBroker, getLogger, getName
-
Field Details
-
DEFAULT_ALGORITHM
-
EMPTY_IV
public static final byte[] EMPTY_IVEmpty IV block. -
algorithm
Type of the block Cipher. Possible values include:- AES/CTR/NoPadding
- AES/CBC/PKCS5Padding
- AES
- DES
- DESede
- RC2
- Blowfish
- ARCFOUR
- etc.
-
password
Password for Symmetric Key Encryption. Using this hard-coded, default password is not secure. Use a custom password instead of this. The required password length is 32, when using "AES/CBC/PKCS5Padding"! -
iv
protected byte[] ivAlgorithm parameters (IV). Can be "null". -
secretKey
SecretKeySpec, can be specified externally. If not specified, it is calculated from the "password". -
encriptors
-
decriptors
-
-
Constructor Details
-
BlockCipherSerializer
public BlockCipherSerializer()Creates a JSON Serializer that uses AES encryption algorithm with the default password (using the hard-coded, default password is not very secure). -
BlockCipherSerializer
Creates a JSON Serializer that uses AES encryption algorithm to encrypt/decrypt messages.- Parameters:
password- password for Symmetric Key Encryption
-
BlockCipherSerializer
Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.- Parameters:
parent- parent Serializer (eg. a JsonSerializer)
-
BlockCipherSerializer
Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.- Parameters:
parent- parent Serializer (eg. a JsonSerializer)password- password for Symmetric Key Encryption
-
BlockCipherSerializer
Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.- Parameters:
parent- parent Serializer (eg. a JsonSerializer)password- password for Symmetric Key Encryptionalgorithm- block Cipher type (eg. "AES", "DES", "DESede", "Blowfish")
-
BlockCipherSerializer
Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.- Parameters:
password- password for Symmetric Key Encryptionalgorithm- block Cipher type (eg. "AES", "DES", "DESede", "Blowfish")iv- IV parameter (can be null)
-
BlockCipherSerializer
Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.- Parameters:
password- password for Symmetric Key Encryptionalgorithm- block Cipher type (eg. "AES", "DES", "DESede", "Blowfish")iv- IV parameter (can be null)
-
BlockCipherSerializer
Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.- Parameters:
parent- parent Serializer (eg. a JsonSerializer)password- password for Symmetric Key Encryptionalgorithm- block Cipher type (eg. "AES", "DES", "DESede", "Blowfish")iv- IV parameter (can be null)
-
BlockCipherSerializer
Creates a Serializer that uses a symmetric encryption algorithm to encrypt/decrypt messages.- Parameters:
parent- parent Serializer (eg. a JsonSerializer)password- password for Symmetric Key Encryptionalgorithm- block Cipher type (eg. "AES", "DES", "DESede", "Blowfish")iv- IV parameter (can be null)
-
-
Method Details
-
started
- Specified by:
startedin interfaceMoleculerLifecycle- Overrides:
startedin classChainedSerializer- Throws:
Exception
-
getAlgorithmName
-
write
- Overrides:
writein classSerializer- Throws:
Exception
-
encrypt
-
read
- Overrides:
readin classSerializer- Throws:
Exception
-
decrypt
-
getEncriptor
-
getDecryptor
-
getAlgorithm
-
setAlgorithm
-
getPassword
-
setPassword
-
getIv
public byte[] getIv() -
setIv
-
setIv
public void setIv(byte[] iv) -
getSecretKey
-
setSecretKey
-