public class RSAKey extends Object implements ByteEncodable, EncryptionKey
Note that due to the nature of this encryption calling decrypt() on data generated by encrypt() on the same key will not yield the original text. With this type of encryption you can only use a key to decrypt the data encrypted by its public/private counterpart.
Use the class RSA to generate a new pair of keys.
Modifier and Type | Field and Description |
---|---|
protected int |
bitLength |
protected BigInteger |
exp |
protected BigInteger |
value |
BIT_LENGTH_UNKNOWN
Modifier | Constructor and Description |
---|---|
protected |
RSAKey() |
|
RSAKey(byte[] encodedBytes,
int offset,
int length)
This creates the key from the bytes as encoded by encodeBytes.
|
|
RSAKey(String exp,
String value,
int bitLength) |
Modifier and Type | Method and Description |
---|---|
byte[] |
decrypt(byte[] encrypted,
int offset,
int length)
Decrypt the data as encrypted by this key's counterpart.
|
byte[] |
encodeBytes() |
int |
encodeBytes(ByteArray dest)
Used to store the key in a stream of bytes.
|
byte[] |
encrypt(byte[] data,
int offset,
int length)
Encrypt the provided data optionally using salt.
|
int |
getBitLength() |
String |
getExp() |
String |
getValue() |
protected BigInteger exp
protected BigInteger value
protected int bitLength
protected RSAKey()
public RSAKey(byte[] encodedBytes, int offset, int length) throws StreamCorruptedException
StreamCorruptedException
public int getBitLength()
getBitLength
in interface EncryptionKey
public String getExp()
public String getValue()
public int encodeBytes(ByteArray dest)
encodeBytes
in interface ByteEncodable
dest
- The destination ByteArray, or null to determine the number of bytes needed to encode.public byte[] encodeBytes()
encodeBytes
in interface ByteEncodable
public byte[] encrypt(byte[] data, int offset, int length) throws IOException
encrypt
in interface EncryptionKey
IOException
public byte[] decrypt(byte[] encrypted, int offset, int length) throws IOException
decrypt
in interface EncryptionKey
IOException