public static final class SecurityTools.RSAHashes extends Object
Contains methods dealing with RSA encryption and decryption.
Modifier and Type | Method and Description |
---|---|
static byte[] |
decrypt(PrivateKey key,
byte[] cipherText)
Decrypts specified text with private key.
|
static byte[] |
decryptFromString(PrivateKey key,
String cipherText)
Decrypts specified text with private key.
|
static byte[] |
encrypt(PublicKey key,
String plainText)
Encrypts specified text with public key.
|
static String |
encryptToString(PublicKey key,
String plainText)
Encrypts specified text with public key.
|
static KeyPair |
generateKeyPair()
Generates a key pair.
|
static KeyPair |
generateKeyPair(boolean saveToFiles,
String fileName)
Generates a key pair and saves them to files matching the specified filename.
|
static PrivateKey |
readPrivateKeyFromBytes(byte[] bytes)
Converts a byte array to a PrivateKey object.
|
static PublicKey |
readPublicKeyFromBytes(byte[] bytes)
Converts a byte array to a PublicKey object.
|
public static KeyPair generateKeyPair() throws IOException, GeneralSecurityException
Generates a key pair.
FileNotFoundException
- if the file is a directory rather than a regular file, or for some other reason cannot be opened for writingIOException
- if an I/O error occursGeneralSecurityException
- if error occurspublic static KeyPair generateKeyPair(boolean saveToFiles, String fileName) throws IOException, GeneralSecurityException
Generates a key pair and saves them to files matching the specified filename.
saveToFiles
- If true KeyPair will be saved to two separate filesfileName
- File name to use to save filesFileNotFoundException
- if the file is a directory rather than a regular file, or for some other reason cannot be opened for writingIOException
- if an I/O error occursGeneralSecurityException
- if error occurspublic static PublicKey readPublicKeyFromBytes(byte[] bytes) throws GeneralSecurityException
Converts a byte array to a PublicKey object.
bytes
- To read fromGeneralSecurityException
- if error occurspublic static PrivateKey readPrivateKeyFromBytes(byte[] bytes) throws GeneralSecurityException
Converts a byte array to a PrivateKey object.
bytes
- To read fromGeneralSecurityException
- if error occurspublic static byte[] encrypt(PublicKey key, String plainText) throws GeneralSecurityException
Encrypts specified text with public key.
key
- Public key to encrypt withplainText
- String to encryptGeneralSecurityException
- if error occurspublic static String encryptToString(PublicKey key, String plainText) throws GeneralSecurityException
Encrypts specified text with public key.
key
- Public key to encrypt withplainText
- String to encryptGeneralSecurityException
- if error occurspublic static byte[] decrypt(PrivateKey key, byte[] cipherText) throws GeneralSecurityException
Decrypts specified text with private key.
key
- Private key to decrypt withcipherText
- String to decryptGeneralSecurityException
- if error occurspublic static byte[] decryptFromString(PrivateKey key, String cipherText) throws GeneralSecurityException
Decrypts specified text with private key.
key
- Private key to decrypt withcipherText
- String to decryptGeneralSecurityException
- if error occursCopyright © 2017–2018 J&G CompTech. All rights reserved.