Class RSA


  • public class RSA
    extends Object
    This is an RSA util class.
    • Constructor Detail

      • RSA

        public RSA()
    • Method Detail

      • genRSAKeypair

        public static RSAKeypair genRSAKeypair()
        Generate RSA key pair
        Returns:
        the RSA key pair
      • encryptRSA

        public static byte[] encryptRSA​(byte[] data,
                                        String key)
        Encrypt data with RSA public key
        Parameters:
        data - the data to encrypt
        key - the RSA public key
        Returns:
        the encrypted data
      • decryptRSA

        public static byte[] decryptRSA​(byte[] data,
                                        String key)
        Decrypt data with RSA private key
        Parameters:
        data - the data to decrypt
        key - the RSA private key
        Returns:
        the decrypted data
      • sign

        public static byte[] sign​(byte[] data,
                                  String k)
        Sign data with RSA private key
        Parameters:
        data - the data to sign
        k - the RSA private key
        Returns:
        the signed data
      • verify

        public static boolean verify​(byte[] data,
                                     String k,
                                     byte[] sign)
        Verify sign with RSA public key
        Parameters:
        data - the data to verify
        k - the RSA public key
        sign - the sign to verify
        Returns:
        true if the sign is valid, false otherwise