Class MAuthSignatureHelper

java.lang.Object
com.mdsol.mauth.util.MAuthSignatureHelper

public class MAuthSignatureHelper extends Object
  • Constructor Details

    • MAuthSignatureHelper

      public MAuthSignatureHelper()
  • Method Details

    • generateUnencryptedSignature

      @Deprecated public static String generateUnencryptedSignature(UUID appUUID, String httpMethod, String resourceUrl, String requestBody, String epochTime)
      Generate string_to_sign for Mauth V1 protocol
      Parameters:
      appUUID - : app uuid
      httpMethod - : Http_Verb
      resourceUrl - : resource_url_path (no host, port or query string; first "/" is included)
      requestBody - : request body string
      epochTime - : current seconds since Epoch
      Returns:
      String httpMethod + "\n" + resourceUrl + "\n" + requestBody + "\n" + app_uuid + "\n" + epochTime
    • generateUnencryptedSignature

      @Deprecated public static byte[] generateUnencryptedSignature(UUID appUUID, String httpMethod, String resourceUrl, byte[] requestBody, String epochTime) throws IOException
      Generate byte_arrary_to_sign for Mauth V1 protocol
      Parameters:
      appUUID - : app uuid
      httpMethod - : Http_Verb
      resourceUrl - : resource_url_path (no host, port or query string; first "/" is included)
      requestBody - : request body byte[]
      epochTime - : current seconds since Epoch
      Returns:
      byte[] httpMethod + "\n" + resourceUrl + "\n" + requestBody + "\n" + app_uuid + "\n" + epochTime
      Throws:
      IOException - When failed to write to ByteArrayOutputStream
    • generateDigestedMessageV1

      @Deprecated public static String generateDigestedMessageV1(MAuthRequest mAuthRequest) throws IOException
      Deprecated.
      Throws:
      IOException
    • createSequenceInputStreamV1

      @Deprecated public static SequenceInputStream createSequenceInputStreamV1(UUID appUUID, String httpMethod, String resourceUrl, InputStream requestBody, String epochTime)
      Deprecated.
    • generateStringToSignV2

      public static String generateStringToSignV2(UUID appUUID, String httpMethod, String resourcePath, String queryParameters, byte[] requestBody, String epochTime) throws MAuthSigningException
      Generate string_to_sign for Mauth V2 protocol
      Parameters:
      appUUID - : application uuid
      httpMethod - : Http_Verb
      resourcePath - : resource_path (Only the path segment of the URL; first "/" is included)
      queryParameters - : request parameters string
      requestBody - : request body byte[]
      epochTime - : current seconds since Epoch
      Returns:
      String httpMethod + "\n" + normalized_resourcePath + "\n" + requestBody_digest + "\n" + app_uuid + "\n" + epochTime + "\n" + encoded_queryParameters
      Throws:
      MAuthSigningException - when generating Unencrypted Signature errors
    • generateStringToSignV2

      public static String generateStringToSignV2(UUID appUUID, String httpMethod, String resourcePath, String queryParameters, InputStream requestBody, String epochTime) throws MAuthSigningException
      Generate string_to_sign for Mauth V2 protocol
      Parameters:
      appUUID - : application uuid
      httpMethod - : Http_Verb
      resourcePath - : resource_path (Only the path segment of the URL; first "/" is included)
      queryParameters - : request parameters string
      requestBody - : request InputStream
      epochTime - : current seconds since Epoch
      Returns:
      String httpMethod + "\n" + normalized_resourcePath + "\n" + requestBody_digest + "\n" + app_uuid + "\n" + epochTime + "\n" + encoded_queryParameters
      Throws:
      MAuthSigningException - when generating Unencrypted Signature errors
    • generateStringToSignV2

      public static String generateStringToSignV2(MAuthRequest mAuthRequest) throws MAuthSigningException
      Generate string_to_sign for Mauth V2 protocol
      Parameters:
      mAuthRequest - : Data from the incoming HTTP request
      Returns:
      String httpMethod + "\n" + normalized_resourcePath + "\n" + requestBody_digest + "\n" + app_uuid + "\n" + epochTime + "\n" + encoded_queryParameters
      Throws:
      MAuthSigningException - when generating Unencrypted Signature errors
    • encryptSignature

      @Deprecated public static String encryptSignature(PrivateKey privateKey, String unencryptedString) throws IOException, org.bouncycastle.crypto.CryptoException
      Deprecated.
      This is used for Mauth V1 protocol, replaced by encryptSignatureRSA(PrivateKey privateKey, String unencryptedString) for Mauth V2 protocol
      Generate base64 encoded signature for Mauth V1 protocol
      Parameters:
      privateKey - the private key of the identity whose signature is going to be generated.
      unencryptedString - the string be signed
      Returns:
      String of Base64 decode the digital signature
      Throws:
      IOException
      org.bouncycastle.crypto.CryptoException
    • encryptSignature

      @Deprecated public static String encryptSignature(PrivateKey privateKey, byte[] unencryptedData) throws IOException, org.bouncycastle.crypto.CryptoException
      Deprecated.
      This is used for Mauth V1 protocol, replaced by encryptSignatureRSA(PrivateKey privateKey, String unencryptedString) for Mauth V2 protocol
      Generate base64 encoded signature for Mauth V1 protocol
      Parameters:
      privateKey - the private key of the identity whose signature is going to be generated.
      unencryptedData - the bytes array be signed
      Returns:
      String of Base64 decode the digital signature
      Throws:
      IOException
      org.bouncycastle.crypto.CryptoException
    • encryptSignature

      @Deprecated public static String encryptSignature(PrivateKey privateKey, InputStream inputStream) throws IOException, org.bouncycastle.crypto.CryptoException
      Deprecated.
      This is used for Mauth V1 protocol, replaced by encryptSignatureRSA(PrivateKey privateKey, String unencryptedString) for Mauth V2 protocol
      Generate base64 encoded signature for Mauth V1 protocol
      Parameters:
      privateKey - the private key of the identity whose signature is going to be generated.
      inputStream - the input stream be signed
      Returns:
      String of Base64 decode the digital signature
      Throws:
      IOException
      org.bouncycastle.crypto.CryptoException
    • decryptSignature

      @Deprecated public static byte[] decryptSignature(PublicKey publicKey, String encryptedSignature)
      Deprecated.
      This is used for Mauth V1 protocol, replaced by verifyRSA(String plainText, String signature, PublicKey publicKey) for Mauth V2 protocol
      Decrypt the encrypted signature for Mauth V1 protocol
      Parameters:
      publicKey - he public key of the identity whose signature is going to be verified.
      encryptedSignature - the signature to be decrypted.
      Returns:
      byte[] decrypted signature
      Throws:
      MAuthSigningException
    • getHexEncodedDigestedString

      public static String getHexEncodedDigestedString(String unencryptedString)
    • getHexEncodedDigestedString

      public static String getHexEncodedDigestedString(byte[] unencryptedData)
    • getHexEncodedDigestedString

      public static String getHexEncodedDigestedString(InputStream inputStream)
    • generateEncryptedQueryParams

      public static String generateEncryptedQueryParams(String encodedQuery)
      generate the query parameters for Mauth V2
      Parameters:
      encodedQuery - the encoded query string
      Returns:
      the sorted-encoded string See https://learn.mdsol.com/display/CA/Building+an+mAuth-Authenticated+API
    • normalizePath

      public static String normalizePath(String encodedPath)
      normalize url-encoded path string
      Parameters:
      encodedPath -
      Returns:
      the normalized string of path
    • encryptSignatureRSA

      public static String encryptSignatureRSA(PrivateKey privateKey, String unencryptedString) throws InvalidKeyException, NoSuchAlgorithmException, SignatureException
      Generate base64 encoded signature using SHA516 with RSA
      Parameters:
      privateKey - the private key of the identity whose signature is going to be generated.
      unencryptedString - the string be signed
      Returns:
      String of Base64 decode the digital signature
      Throws:
      InvalidKeyException
      NoSuchAlgorithmException
      SignatureException
    • verifyRSA

      public static boolean verifyRSA(String plainText, String signature, PublicKey publicKey) throws Exception
      Verify SHA512-RSA signature
      Parameters:
      plainText - the string be verified
      signature - the signature to be verified.
      publicKey - he public key of the identity whose signature is going to be verified.
      Returns:
      boolean
      Throws:
      Exception