Class MAuthSignatureHelper


  • public class MAuthSignatureHelper
    extends java.lang.Object
    • Constructor Detail

      • MAuthSignatureHelper

        public MAuthSignatureHelper()
    • Method Detail

      • generateUnencryptedSignature

        @Deprecated
        public static java.lang.String generateUnencryptedSignature​(java.util.UUID appUUID,
                                                                    java.lang.String httpMethod,
                                                                    java.lang.String resourceUrl,
                                                                    java.lang.String requestBody,
                                                                    java.lang.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​(java.util.UUID appUUID,
                                                          java.lang.String httpMethod,
                                                          java.lang.String resourceUrl,
                                                          byte[] requestBody,
                                                          java.lang.String epochTime)
                                                   throws java.io.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:
        java.io.IOException - When failed to write to ByteArrayOutputStream
      • generateDigestedMessageV1

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

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

        public static java.lang.String generateStringToSignV2​(java.util.UUID appUUID,
                                                              java.lang.String httpMethod,
                                                              java.lang.String resourcePath,
                                                              java.lang.String queryParameters,
                                                              byte[] requestBody,
                                                              java.lang.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 java.lang.String generateStringToSignV2​(java.util.UUID appUUID,
                                                              java.lang.String httpMethod,
                                                              java.lang.String resourcePath,
                                                              java.lang.String queryParameters,
                                                              java.io.InputStream requestBody,
                                                              java.lang.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 java.lang.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 java.lang.String encryptSignature​(java.security.PrivateKey privateKey,
                                                        java.lang.String unencryptedString)
                                                 throws java.io.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:
        java.io.IOException
        org.bouncycastle.crypto.CryptoException
      • encryptSignature

        @Deprecated
        public static java.lang.String encryptSignature​(java.security.PrivateKey privateKey,
                                                        byte[] unencryptedData)
                                                 throws java.io.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:
        java.io.IOException
        org.bouncycastle.crypto.CryptoException
      • encryptSignature

        @Deprecated
        public static java.lang.String encryptSignature​(java.security.PrivateKey privateKey,
                                                        java.io.InputStream inputStream)
                                                 throws java.io.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:
        java.io.IOException
        org.bouncycastle.crypto.CryptoException
      • decryptSignature

        @Deprecated
        public static byte[] decryptSignature​(java.security.PublicKey publicKey,
                                              java.lang.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 java.lang.String getHexEncodedDigestedString​(java.lang.String unencryptedString)
      • getHexEncodedDigestedString

        public static java.lang.String getHexEncodedDigestedString​(byte[] unencryptedData)
      • getHexEncodedDigestedString

        public static java.lang.String getHexEncodedDigestedString​(java.io.InputStream inputStream)
      • generateEncryptedQueryParams

        public static java.lang.String generateEncryptedQueryParams​(java.lang.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 java.lang.String normalizePath​(java.lang.String encodedPath)
        normalize url-encoded path string
        Parameters:
        encodedPath -
        Returns:
        the normalized string of path
      • encryptSignatureRSA

        public static java.lang.String encryptSignatureRSA​(java.security.PrivateKey privateKey,
                                                           java.lang.String unencryptedString)
                                                    throws java.security.InvalidKeyException,
                                                           java.security.NoSuchAlgorithmException,
                                                           java.security.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:
        java.security.InvalidKeyException
        java.security.NoSuchAlgorithmException
        java.security.SignatureException
      • verifyRSA

        public static boolean verifyRSA​(java.lang.String plainText,
                                        java.lang.String signature,
                                        java.security.PublicKey publicKey)
                                 throws java.lang.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:
        java.lang.Exception