Class RsaCipher
- java.lang.Object
-
- org.activecomponents.udp.asymciphers.RsaCipher
-
- All Implemented Interfaces:
IAsymCipher
public class RsaCipher extends java.lang.Object implements IAsymCipher
-
-
Field Summary
Fields Modifier and Type Field Description protected org.bouncycastle.crypto.params.AsymmetricKeyParameter
foreignpublic
Public key of the communication partner.protected org.bouncycastle.crypto.AsymmetricCipherKeyPair
keypair
Keypairprotected org.bouncycastle.crypto.AsymmetricBlockCipher
oaeprsa
OAEP engine.protected org.bouncycastle.crypto.Signer
pssrsa
PSS engine.
-
Constructor Summary
Constructors Constructor Description RsaCipher(RsaKeyProvider kp)
RsaCipher(org.bouncycastle.crypto.AsymmetricCipherKeyPair keypair)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.bouncycastle.crypto.params.AsymmetricKeyParameter
byteArrayToKey(byte[] enckey)
Converts a key from binary form.byte[]
decrypt(byte[] ciphertext)
Decrypts a message.byte[]
decryptAndVerify(byte[] ciphertext, boolean verifywithforeign)
Decrypts a message and verifies the signature.byte[]
encrypt(byte[] plain, boolean foreign)
Encrypts a message using a public key.byte[]
keyToByteArray(org.bouncycastle.crypto.params.AsymmetricKeyParameter key)
Converts a key to binary form.static void
main(java.lang.String[] args)
boolean
setForeign(byte[] foreignpublic)
Sets the public key of the communication partner.byte[]
sign(byte[] msg)
Signs a message.byte[]
signAndEncrypt(byte[] msg, boolean encryptwithforeign)
Signs a message and encrypts a message.byte[]
verify(byte[] msgwithsig, boolean foreign)
Verifies a message.
-
-
-
Field Detail
-
keypair
protected org.bouncycastle.crypto.AsymmetricCipherKeyPair keypair
Keypair
-
foreignpublic
protected org.bouncycastle.crypto.params.AsymmetricKeyParameter foreignpublic
Public key of the communication partner.
-
pssrsa
protected org.bouncycastle.crypto.Signer pssrsa
PSS engine.
-
oaeprsa
protected org.bouncycastle.crypto.AsymmetricBlockCipher oaeprsa
OAEP engine.
-
-
Constructor Detail
-
RsaCipher
public RsaCipher(RsaKeyProvider kp)
-
RsaCipher
public RsaCipher(org.bouncycastle.crypto.AsymmetricCipherKeyPair keypair)
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
-
setForeign
public boolean setForeign(byte[] foreignpublic)
Sets the public key of the communication partner.- Specified by:
setForeign
in interfaceIAsymCipher
- Parameters:
foreignpublic
- The public key.- Returns:
- False, if the key was invalid.
-
encrypt
public byte[] encrypt(byte[] plain, boolean foreign)
Encrypts a message using a public key.- Parameters:
plain
- The plain text.foreign
- True, if the foreign public key should be used, false, if the innate one should be used.- Returns:
- The cipher text.
-
decrypt
public byte[] decrypt(byte[] ciphertext)
Decrypts a message.- Parameters:
ciphertext
- The cipher text.- Returns:
- The plain text or null if decryption failed.
-
sign
public byte[] sign(byte[] msg)
Signs a message.- Parameters:
msg
- The message.- Returns:
- The message with signature.
-
verify
public byte[] verify(byte[] msgwithsig, boolean foreign)
Verifies a message.- Parameters:
msg
- The message with signature.foreign
- True, if the foreign public key should be used, false, if the innate one should be used.- Returns:
- The message or null if the verification failed.
-
signAndEncrypt
public byte[] signAndEncrypt(byte[] msg, boolean encryptwithforeign)
Signs a message and encrypts a message.- Specified by:
signAndEncrypt
in interfaceIAsymCipher
- Parameters:
msg
- The message.encryptwithforeign
- True, if the foreign public key should be used for encryption, false, if the innate one should be used.- Returns:
- The message with signature, encrypted.
-
decryptAndVerify
public byte[] decryptAndVerify(byte[] ciphertext, boolean verifywithforeign)
Decrypts a message and verifies the signature.- Specified by:
decryptAndVerify
in interfaceIAsymCipher
- Parameters:
msg
- The signed and encrypted message.encryptwithforeign
- True, if the foreign public key should be used for verification, false, if the innate one should be used.- Returns:
- The message, null if verification failed.
-
keyToByteArray
public byte[] keyToByteArray(org.bouncycastle.crypto.params.AsymmetricKeyParameter key)
Converts a key to binary form.- Specified by:
keyToByteArray
in interfaceIAsymCipher
- Parameters:
key
- The key.- Returns:
- The binary form of the key.
-
byteArrayToKey
public org.bouncycastle.crypto.params.AsymmetricKeyParameter byteArrayToKey(byte[] enckey)
Converts a key from binary form.- Specified by:
byteArrayToKey
in interfaceIAsymCipher
- Parameters:
enckey
- The encoded key.- Returns:
- The key.
-
-