Class JsonSignatureUtil


  • public final class JsonSignatureUtil
    extends java.lang.Object
    JSON signature based on https://global.alipay.com/docs/ac/gr/signature#d2e38597
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static JsonSignatureUtil getInstance()
      Get the instance
      java.lang.String sign​(java.lang.String provider, java.lang.String signatureAlgorithm, java.security.PrivateKey privateKey, java.lang.String inputJson)
      Sign a json
      boolean verify​(java.lang.String provider, java.lang.String signatureAlgorithm, java.security.PublicKey publicKey, java.lang.String requestToVerify)
      Verify signed json content
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getInstance

        public static JsonSignatureUtil getInstance()
        Get the instance
        Returns:
        the instance
      • sign

        public java.lang.String sign​(java.lang.String provider,
                                     java.lang.String signatureAlgorithm,
                                     java.security.PrivateKey privateKey,
                                     java.lang.String inputJson)
                              throws java.security.GeneralSecurityException
        Sign a json
        Parameters:
        provider - the provider
        signatureAlgorithm - the signature algorithm like: SHA1withRSA, SHA1withDSA, RSA...
        privateKey - the private key
        inputJson - the input json
        Returns:
        the signed json
        Throws:
        java.security.GeneralSecurityException - In case of a security exception
        java.lang.IllegalArgumentException - In case of invalid input
      • verify

        public boolean verify​(java.lang.String provider,
                              java.lang.String signatureAlgorithm,
                              java.security.PublicKey publicKey,
                              java.lang.String requestToVerify)
                       throws java.security.GeneralSecurityException
        Verify signed json content
        Parameters:
        provider - the provider
        signatureAlgorithm - the signature algorithm like: SHA1withRSA, SHA1withDSA, RSA...
        publicKey - the public key
        requestToVerify - the request to verify
        Returns:
        true if the signature match with the signed request
        Throws:
        java.security.GeneralSecurityException - In case of a security exception
        java.lang.IllegalArgumentException - In case of invalid input