Updated on 2022-02-21 GMT+08:00

RSAUtils

Path

com.roma.apic.livedata.common.v1.RSAUtils

Description

This class is used to provide the RSA encryption and decryption methods.

Constructor Details

public RSAUtils()

Constructs an RSAUtils without parameters.

Method List

Returned Type

Method and Description

static byte[]

decodeBase64(String base64)

Decode a Base64 character string to binary data.

static byte[]

decrypt(java.security.PrivateKey privateKey, byte[] encryptData)

Decrypt data using the RSA algorithm.

static String

decrypt(String source, java.security.interfaces.RSAPrivateKey privateKey)

Decrypt data using the RSA algorithm.

static String

encodeBase64(byte[] bytes)

Encode binary data to a Base64 character string.

static byte[]

encrypt(java.security.PublicKey publicKey, byte[] source)

Encrypt data using the RSA algorithm.

static String

encrypt(String source, java.security.PublicKey publicKey)

Encrypt data using the RSA algorithm.

static org.bouncycastle.jce.provider.BouncyCastleProvider

getInstance()

Obtain the encryption algorithm provider.

static java.security.interfaces.RSAPrivateKey

getPrivateKey(byte[] privateKeyByte)

Create the RSA private key by using the private key of the x509 format.

static java.security.interfaces.RSAPrivateKey

getPrivateKey(String privateKeyByte)

Create the RSA private key by using the private key of the x509 format.

static java.security.interfaces.RSAPrivateKey

getPrivateKey(String modulus, String exponent)

Create an RSA private key by using the modulus and exponent.

static java.security.interfaces.RSAPublicKey

getPublicKey(byte[] publicKeyByte)

Create the RSA public key by using the private public of the x509 format.

static java.security.interfaces.RSAPublicKey

getPublicKey(String publicKeyByte)

Create the RSA public key by using the private public of the x509 format.

static java.security.PublicKey

getPublicKey(String modulus, String exponent)

Create an RSA public key by using the modulus and exponent.

Method Details

  • public static byte[] decodeBase64(String base64)

    Decode a Base64 character string to binary data.

    Input Parameter

    base64 indicates the data encoded using Base64.

    Returns

    Data decoded by using Base64

    Throws

    Exception

  • public static byte[] decrypt(java.security.PrivateKey privateKey, byte[] encryptData)

    Decrypt data using the RSA algorithm.

    Input Parameter

    • privateKey indicates a private key.
    • encryptData indicates the data to be decrypted.

    Returns

    Decrypted data.

    Throws

    • javax.crypto.IllegalBlockSizeException
    • javax.crypto.BadPaddingException
    • java.security.InvalidKeyException
    • java.security.NoSuchAlgorithmException
    • javax.crypto.NoSuchPaddingException
  • public static String encrypt(String source, java.security.interfaces.RSAPrivateKey privateKey)

    Encrypt data using the RSA algorithm.

    Input Parameter

    • source indicates data to be encrypted.
    • privateKey indicates a private key.

    Returns

    Encrypted data.

  • public static String encodeBase64(byte[] bytes)

    Encode binary data to a Base64 character string.

    Input Parameter

    bytes indicates data to be encoded.

    Returns

    Base64 encoding.

    Throws

    Exception

  • public static byte[] encrypt(java.security.PublicKey publicKey, byte[] source)

    Encrypt data using the RSA algorithm.

    Input Parameter

    • publicKey indicates a public key.
    • source indicates data to be decrypted.

    Returns

    Encrypted data content.

    Throws

    Exception

  • public static String encrypt(String source, java.security.PublicKey publicKey)

    Encrypt data using the RSA algorithm.

    Input Parameter

    • source indicates the content to be encrypted.
    • publicKey indicates a public key.

    Returns

    Encrypted data content.

    Throws

    Exception

  • public static org.bouncycastle.jce.provider.BouncyCastleProvider getInstance()

    Obtain the encryption algorithm provider.

    Returns

    Encryption algorithm provider.

  • public static java.security.interfaces.RSAPrivateKey getPrivateKey(byte[] privateKeyByte)

    Create the RSA private key by using the private key of the x509 format.

    Input Parameter

    privateKeyByte indicates the private key encoded in x509 format

    Returns

    Private key.

    Throws

    • java.security.spec.InvalidKeySpecException
    • java.security.NoSuchAlgorithmException
  • public static java.security.interfaces.RSAPrivateKey getPrivateKey(String privateKeyByte)

    Create the RSA private key by using the private key of the x509 format.

    Input Parameter

    privateKeyByte indicates the private key encoded in x509 format

    Returns

    Private key.

    Throws

    Exception

  • public static java.security.interfaces.RSAPrivateKey getPrivateKey(String modulus, String exponent)

    Create an RSA private key by using the modulus and exponent.

    Input Parameter

    • modulus indicates the modulus required for generating a private key.
    • exponent indicates the exponent required for generating a private key.

    Returns

    RSA private key.

  • public static java.security.interfaces.RSAPublicKey getPublicKey(byte[] publicKeyByte)

    Create the RSA public key by using the private public encoded in x509 format.

    Input Parameter

    publicKeyByte indicates the public key encoded in x509 format.

    Returns

    Public key.

    Throws

    • java.security.NoSuchAlgorithmException
    • java.security.spec.InvalidKeySpecException
  • public static java.security.PublicKey getPublicKey(String modulus, String exponent)

    Create an RSA public key by using the modulus and exponent.

    Input Parameter

    • modulus indicates the modulus required for generating a public key.
    • exponent indicates the exponent required for generating a public key.

    Returns

    RSA public key.