|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.eu.miscedautils.CommonUtils.RSAEncryptUtil
public class RSAEncryptUtil
Title: RSAEncryptUtil
Description: Utility class that helps encrypt and decrypt strings using RSA algorithm
Constructor Summary | |
---|---|
RSAEncryptUtil()
|
Method Summary | |
---|---|
static byte[] |
copyBytes(byte[] arr,
int length)
|
static byte[] |
decodeBASE64(java.lang.String text)
Decode BASE64 encoded string to bytes array |
static byte[] |
decrypt(byte[] text,
java.security.PrivateKey key)
Decrypt text using private key |
static java.lang.String |
decrypt(java.lang.String text,
java.security.PrivateKey key)
Decrypt BASE64 encoded text using private key |
static void |
decryptFile(java.lang.String srcFileName,
java.lang.String destFileName,
java.security.PrivateKey key)
Decrypt file using 1024 RSA encryption |
static java.lang.String |
encodeBASE64(byte[] bytes)
Encode bytes array to BASE64 string |
static byte[] |
encrypt(byte[] text,
java.security.PublicKey key)
Encrypt a text using public key. |
static java.lang.String |
encrypt(java.lang.String text,
java.security.PublicKey key)
Encrypt a text using public key. |
static void |
encryptDecryptFile(java.lang.String srcFileName,
java.lang.String destFileName,
java.security.Key key,
int cipherMode)
Encrypt and Decrypt files using 1024 RSA encryption |
static void |
encryptFile(java.lang.String srcFileName,
java.lang.String destFileName,
java.security.PublicKey key)
Encrypt file using 1024 RSA encryption |
static java.security.KeyPair |
generateKey()
Generate key which contains a pair of private and public key using 1024 bytes |
static java.lang.String |
getKeyAsString(java.security.Key key)
Convert a Key to string encoded as BASE64 |
static java.security.PrivateKey |
getPrivateKeyFromString(java.lang.String key)
Generates Private Key from BASE64 encoded string |
static java.security.PublicKey |
getPublicKeyFromString(java.lang.String key)
Generates Public Key from BASE64 encoded string |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public RSAEncryptUtil()
Method Detail |
---|
public static java.security.KeyPair generateKey() throws java.security.NoSuchAlgorithmException
java.security.NoSuchAlgorithmException
public static byte[] encrypt(byte[] text, java.security.PublicKey key) throws java.lang.Exception
text
- The original unencrypted textkey
- The public key
java.lang.Exception
public static java.lang.String encrypt(java.lang.String text, java.security.PublicKey key) throws java.lang.Exception
text
- The original unencrypted textkey
- The public key
java.lang.Exception
public static byte[] decrypt(byte[] text, java.security.PrivateKey key) throws java.lang.Exception
text
- The encrypted textkey
- The private key
java.lang.Exception
public static java.lang.String decrypt(java.lang.String text, java.security.PrivateKey key) throws java.lang.Exception
text
- The encrypted text, encoded as BASE64key
- The private key
java.lang.Exception
public static java.lang.String getKeyAsString(java.security.Key key)
key
- The key (private or public)
public static java.security.PrivateKey getPrivateKeyFromString(java.lang.String key) throws java.lang.Exception
key
- BASE64 encoded string which represents the key
java.lang.Exception
public static java.security.PublicKey getPublicKeyFromString(java.lang.String key) throws java.lang.Exception
key
- BASE64 encoded string which represents the key
java.lang.Exception
public static java.lang.String encodeBASE64(byte[] bytes)
bytes
-
public static byte[] decodeBASE64(java.lang.String text) throws java.io.IOException
text
- The string
java.io.IOException
public static void encryptFile(java.lang.String srcFileName, java.lang.String destFileName, java.security.PublicKey key) throws java.lang.Exception
srcFileName
- Source file namedestFileName
- Destination file namekey
- The key. For encryption this is the Private Key and for decryption this is the public keycipherMode
- Cipher Mode
java.lang.Exception
public static void decryptFile(java.lang.String srcFileName, java.lang.String destFileName, java.security.PrivateKey key) throws java.lang.Exception
srcFileName
- Source file namedestFileName
- Destination file namekey
- The key. For encryption this is the Private Key and for decryption this is the public keycipherMode
- Cipher Mode
java.lang.Exception
public static void encryptDecryptFile(java.lang.String srcFileName, java.lang.String destFileName, java.security.Key key, int cipherMode) throws java.lang.Exception
srcFileName
- Source file namedestFileName
- Destination file namekey
- The key. For encryption this is the Private Key and for decryption this is the public keycipherMode
- Cipher Mode
java.lang.Exception
public static byte[] copyBytes(byte[] arr, int length)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |