Package com.mdsol.mauth.util
Class MAuthSignatureHelper
java.lang.Object
com.mdsol.mauth.util.MAuthSignatureHelper
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SequenceInputStreamcreateSequenceInputStreamV1(UUID appUUID, String httpMethod, String resourceUrl, InputStream requestBody, String epochTime) Deprecated.static byte[]decryptSignature(PublicKey publicKey, String encryptedSignature) Deprecated.static StringencryptSignature(PrivateKey privateKey, byte[] unencryptedData) Deprecated.This is used for Mauth V1 protocol, replaced byencryptSignatureRSA(PrivateKey privateKey, String unencryptedString)for Mauth V2 protocolstatic StringencryptSignature(PrivateKey privateKey, InputStream inputStream) Deprecated.This is used for Mauth V1 protocol, replaced byencryptSignatureRSA(PrivateKey privateKey, String unencryptedString)for Mauth V2 protocolstatic StringencryptSignature(PrivateKey privateKey, String unencryptedString) Deprecated.This is used for Mauth V1 protocol, replaced byencryptSignatureRSA(PrivateKey privateKey, String unencryptedString)for Mauth V2 protocolstatic StringencryptSignatureRSA(PrivateKey privateKey, String unencryptedString) Generate base64 encoded signature using SHA516 with RSAstatic StringgenerateDigestedMessageV1(MAuthRequest mAuthRequest) Deprecated.static StringgenerateEncryptedQueryParams(String encodedQuery) generate the query parameters for Mauth V2static StringgenerateStringToSignV2(MAuthRequest mAuthRequest) Generate string_to_sign for Mauth V2 protocolstatic StringgenerateStringToSignV2(UUID appUUID, String httpMethod, String resourcePath, String queryParameters, byte[] requestBody, String epochTime) Generate string_to_sign for Mauth V2 protocolstatic StringgenerateStringToSignV2(UUID appUUID, String httpMethod, String resourcePath, String queryParameters, InputStream requestBody, String epochTime) Generate string_to_sign for Mauth V2 protocolstatic byte[]generateUnencryptedSignature(UUID appUUID, String httpMethod, String resourceUrl, byte[] requestBody, String epochTime) Deprecated.This is used for Mauth V1 protocol, replaced bygenerateStringToSignV2(UUID appUUID, String httpMethod, String resourceUrl, String queryParameters, byte[] requestBody, String epochTime)for Mauth V2 protocolstatic StringgenerateUnencryptedSignature(UUID appUUID, String httpMethod, String resourceUrl, String requestBody, String epochTime) Deprecated.This is used for Mauth V1 protocol, replaced bygenerateStringToSignV2(UUID appUUID, String httpMethod, String resourceUrl, String queryParameters, byte[] requestBody, String epochTime)for Mauth V2 protocolstatic StringgetHexEncodedDigestedString(byte[] unencryptedData) static StringgetHexEncodedDigestedString(InputStream inputStream) static StringgetHexEncodedDigestedString(String unencryptedString) static StringnormalizePath(String encodedPath) normalize url-encoded path stringstatic booleanVerify SHA512-RSA signature
-
Constructor Details
-
MAuthSignatureHelper
public MAuthSignatureHelper()
-
-
Method Details
-
generateUnencryptedSignature
@Deprecated public static String generateUnencryptedSignature(UUID appUUID, String httpMethod, String resourceUrl, String requestBody, String epochTime) Deprecated.This is used for Mauth V1 protocol, replaced bygenerateStringToSignV2(UUID appUUID, String httpMethod, String resourceUrl, String queryParameters, byte[] requestBody, String epochTime)for Mauth V2 protocolGenerate string_to_sign for Mauth V1 protocol- Parameters:
appUUID- : app uuidhttpMethod- : Http_VerbresourceUrl- : resource_url_path (no host, port or query string; first "/" is included)requestBody- : request body stringepochTime- : 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 Deprecated.This is used for Mauth V1 protocol, replaced bygenerateStringToSignV2(UUID appUUID, String httpMethod, String resourceUrl, String queryParameters, byte[] requestBody, String epochTime)for Mauth V2 protocolGenerate byte_arrary_to_sign for Mauth V1 protocol- Parameters:
appUUID- : app uuidhttpMethod- : Http_VerbresourceUrl- : 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 uuidhttpMethod- : Http_VerbresourcePath- : resource_path (Only the path segment of the URL; first "/" is included)queryParameters- : request parameters stringrequestBody- : 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 uuidhttpMethod- : Http_VerbresourcePath- : resource_path (Only the path segment of the URL; first "/" is included)queryParameters- : request parameters stringrequestBody- : request InputStreamepochTime- : 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
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 byencryptSignatureRSA(PrivateKey privateKey, String unencryptedString)for Mauth V2 protocolGenerate 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:
IOExceptionorg.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 byencryptSignatureRSA(PrivateKey privateKey, String unencryptedString)for Mauth V2 protocolGenerate 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:
IOExceptionorg.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 byencryptSignatureRSA(PrivateKey privateKey, String unencryptedString)for Mauth V2 protocolGenerate 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:
IOExceptionorg.bouncycastle.crypto.CryptoException
-
decryptSignature
Deprecated.This is used for Mauth V1 protocol, replaced byverifyRSA(String plainText, String signature, PublicKey publicKey)for Mauth V2 protocolDecrypt 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
-
getHexEncodedDigestedString
-
getHexEncodedDigestedString
-
generateEncryptedQueryParams
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
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:
InvalidKeyExceptionNoSuchAlgorithmExceptionSignatureException
-
verifyRSA
public static boolean verifyRSA(String plainText, String signature, PublicKey publicKey) throws Exception Verify SHA512-RSA signature- Parameters:
plainText- the string be verifiedsignature- the signature to be verified.publicKey- he public key of the identity whose signature is going to be verified.- Returns:
- boolean
- Throws:
Exception
-
verifyRSA(String plainText, String signature, PublicKey publicKey)for Mauth V2 protocol