public class RsaSerializer extends java.lang.Object implements ISerializer
String aDataToSerialize = "Hello";
KeyPairGenerator aKeyPairGenerator = KeyPairGenerator.getInstance("RSA");
aKeyPairGenerator.initialize(1024);
KeyPair aKeyPair = aKeyPairGenerator.generateKeyPair();
RSAPrivateKey aPrivateKey = (RSAPrivateKey)aKeyPair.getPrivate();
RSAPublicKey aPublicKey = (RSAPublicKey)aKeyPair.getPublic();
RsaSerializer aSerializer = new RsaSerializer(aPublicKey, aPrivateKey);
Object aSerializedData = aSerializer.serialize(aDataToSerialize, String.class);
String aDeserializedData = aSerializer.deserialize(aSerializedData, String.class);
Constructor and Description |
---|
RsaSerializer(java.security.interfaces.RSAPublicKey publicKey,
java.security.interfaces.RSAPrivateKey privateKey)
Constructs the RSA serializer with default paraneters.
|
RsaSerializer(java.security.interfaces.RSAPublicKey publicKey,
java.security.interfaces.RSAPrivateKey privateKey,
int aesBitSize,
ISerializer underlyingSerializer)
Constructs the RSA serializer with custom parameters.
|
Modifier and Type | Method and Description |
---|---|
<T> T |
deserialize(java.lang.Object serializedData,
java.lang.Class<T> clazz)
Deserializes data.
|
java.lang.String |
getCipherTransformationSpecification()
Gets name of used cipher transformation name.
|
<T> java.lang.Object |
serialize(T dataToSerialize,
java.lang.Class<T> clazz)
Serializes data.
|
RsaSerializer |
setCipherTransformationSpecification(java.lang.String cipherTransformationName)
Sets name of the cipher transformation.
|
public RsaSerializer(java.security.interfaces.RSAPublicKey publicKey, java.security.interfaces.RSAPrivateKey privateKey)
publicKey
- public key used for serialization. It can be null if the serializer will be used only for deserialization.privateKey
- private key used for deserialization. It can be null if the serializer will be used only for serialization.public RsaSerializer(java.security.interfaces.RSAPublicKey publicKey, java.security.interfaces.RSAPrivateKey privateKey, int aesBitSize, ISerializer underlyingSerializer)
publicKey
- publicKey public key used for serialization. It can be null if the serializer will be used only for deserialization.privateKey
- private key used for deserialization. It can be null if the serializer will be used only for serialization.aesBitSize
- size of the random key generated for the AES encryption, 128, 256, ... Default value is 128.underlyingSerializer
- underlying serializer used to serialize/deserialize data e.g. XmlStringSerializerpublic RsaSerializer setCipherTransformationSpecification(java.lang.String cipherTransformationName)
cipherTransformationName
- sets the transformation name in format algorithmName/algorithmMode/algorithmPadding
The default value which is compatible with .NET is RSA/ECB/PKCS1Padding.public java.lang.String getCipherTransformationSpecification()
public <T> java.lang.Object serialize(T dataToSerialize, java.lang.Class<T> clazz) throws java.lang.Exception
serialize
in interface ISerializer
dataToSerialize
- Data to be serialized.clazz
- represents the serialized type.java.lang.Exception
- If the serialization fails.public <T> T deserialize(java.lang.Object serializedData, java.lang.Class<T> clazz) throws java.lang.Exception
deserialize
in interface ISerializer
serializedData
- Data to be deserialized.java.lang.Exception
- If the deserialization fails.