Class RSA


  • public class RSA
    extends Object
    • Constructor Detail

      • RSA

        public RSA()
    • 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 - Message
        pubKey - 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 array
        privKey - 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