Package com.mdsol.mauth.util
Class MAuthSignatureHelper
- java.lang.Object
-
- com.mdsol.mauth.util.MAuthSignatureHelper
-
public class MAuthSignatureHelper extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description MAuthSignatureHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.io.SequenceInputStreamcreateSequenceInputStreamV1(java.util.UUID appUUID, java.lang.String httpMethod, java.lang.String resourceUrl, java.io.InputStream requestBody, java.lang.String epochTime)Deprecated.static byte[]decryptSignature(java.security.PublicKey publicKey, java.lang.String encryptedSignature)Deprecated.This is used for Mauth V1 protocol, replaced byverifyRSA(String plainText, String signature, PublicKey publicKey)for Mauth V2 protocolstatic java.lang.StringencryptSignature(java.security.PrivateKey privateKey, byte[] unencryptedData)Deprecated.This is used for Mauth V1 protocol, replaced byencryptSignatureRSA(PrivateKey privateKey, String unencryptedString)for Mauth V2 protocolstatic java.lang.StringencryptSignature(java.security.PrivateKey privateKey, java.io.InputStream inputStream)Deprecated.This is used for Mauth V1 protocol, replaced byencryptSignatureRSA(PrivateKey privateKey, String unencryptedString)for Mauth V2 protocolstatic java.lang.StringencryptSignature(java.security.PrivateKey privateKey, java.lang.String unencryptedString)Deprecated.This is used for Mauth V1 protocol, replaced byencryptSignatureRSA(PrivateKey privateKey, String unencryptedString)for Mauth V2 protocolstatic java.lang.StringencryptSignatureRSA(java.security.PrivateKey privateKey, java.lang.String unencryptedString)Generate base64 encoded signature using SHA516 with RSAstatic java.lang.StringgenerateDigestedMessageV1(MAuthRequest mAuthRequest)Deprecated.static java.lang.StringgenerateEncryptedQueryParams(java.lang.String encodedQuery)generate the query parameters for Mauth V2static java.lang.StringgenerateStringToSignV2(MAuthRequest mAuthRequest)Generate string_to_sign for Mauth V2 protocolstatic java.lang.StringgenerateStringToSignV2(java.util.UUID appUUID, java.lang.String httpMethod, java.lang.String resourcePath, java.lang.String queryParameters, byte[] requestBody, java.lang.String epochTime)Generate string_to_sign for Mauth V2 protocolstatic java.lang.StringgenerateStringToSignV2(java.util.UUID appUUID, java.lang.String httpMethod, java.lang.String resourcePath, java.lang.String queryParameters, java.io.InputStream requestBody, java.lang.String epochTime)Generate string_to_sign for Mauth V2 protocolstatic byte[]generateUnencryptedSignature(java.util.UUID appUUID, java.lang.String httpMethod, java.lang.String resourceUrl, byte[] requestBody, java.lang.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 java.lang.StringgenerateUnencryptedSignature(java.util.UUID appUUID, java.lang.String httpMethod, java.lang.String resourceUrl, java.lang.String requestBody, java.lang.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 java.lang.StringgetHexEncodedDigestedString(byte[] unencryptedData)static java.lang.StringgetHexEncodedDigestedString(java.io.InputStream inputStream)static java.lang.StringgetHexEncodedDigestedString(java.lang.String unencryptedString)static java.lang.StringnormalizePath(java.lang.String encodedPath)normalize url-encoded path stringstatic booleanverifyRSA(java.lang.String plainText, java.lang.String signature, java.security.PublicKey publicKey)Verify SHA512-RSA signature
-
-
-
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)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(java.util.UUID appUUID, java.lang.String httpMethod, java.lang.String resourceUrl, byte[] requestBody, java.lang.String epochTime) throws java.io.IOExceptionDeprecated.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:
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 MAuthSigningExceptionGenerate 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 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 MAuthSigningExceptionGenerate 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
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.CryptoExceptionDeprecated.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:
java.io.IOExceptionorg.bouncycastle.crypto.CryptoException
-
encryptSignature
@Deprecated public static java.lang.String encryptSignature(java.security.PrivateKey privateKey, byte[] unencryptedData) throws java.io.IOException, org.bouncycastle.crypto.CryptoExceptionDeprecated.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:
java.io.IOExceptionorg.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.CryptoExceptionDeprecated.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:
java.io.IOExceptionorg.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 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
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.SignatureExceptionGenerate 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.InvalidKeyExceptionjava.security.NoSuchAlgorithmExceptionjava.security.SignatureException
-
verifyRSA
public static boolean verifyRSA(java.lang.String plainText, java.lang.String signature, java.security.PublicKey publicKey) throws java.lang.ExceptionVerify 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:
java.lang.Exception
-
-