Package net.craftions.api.encryption
Class RSA
- java.lang.Object
-
- net.craftions.api.encryption.RSA
-
public class RSA extends Object
-
-
Constructor Summary
Constructors Constructor Description RSA()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Stringdecrypt(byte[] message, PrivateKey privKey)Decrypt messagestatic byte[]encrypt(String message, PublicKey pubKey)Encrypt a messagestatic KeyPairgen(int size)Generate Keysstatic @Experimental PrivateKeyprivFromString(String s)Get Private Key from String.static PublicKeypubFromString(String s)Get Public Key from String.
-
-
-
Method Detail
-
gen
public static KeyPair gen(int size) throws Exception
Generate Keys- Parameters:
size- Keysize- Returns:
- KeyPair
- Throws:
Exception- if anything goes wrong
-
encrypt
public static byte[] encrypt(String message, PublicKey pubKey) throws Exception
Encrypt a message- Parameters:
message- MessagepubKey- Public Key- Returns:
- encrypted message as byte array
- Throws:
Exception- if anything goes wrong
-
decrypt
public static String decrypt(byte[] message, PrivateKey privKey) throws Exception
Decrypt message- Parameters:
message- encrypted message as byte arrayprivKey- Private Key- Returns:
- decrypted Message as String
- Throws:
Exception- if anything goes wrong
-
pubFromString
public static PublicKey pubFromString(String s)
Get Public Key from String. You can use this for reading the public key form a file.- Parameters:
s- Public Key as String- Returns:
- Public Key Object
-
privFromString
@Experimental public static @Experimental PrivateKey privFromString(String s)
Get Private Key from String. You can use this for reading the private key form a file.- Parameters:
s- Private Key as String- Returns:
- Private Key Object
-
-