Package com.stripe.net
Class Webhook.Signature
java.lang.Object
com.stripe.net.Webhook.Signature
- Enclosing class:
- Webhook
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringgenerateSignatureHeader(String payload, String secret) Generates aStripe-Signatureheader for the given payload and secret using the current timestamp.static StringgenerateSignatureHeader(String payload, String secret, long timestamp) Compute theStripe-Signatureheader for a given webhook body & secret.static booleanverifyHeader(String payload, String sigHeader, String secret, long tolerance) Verifies the signature header sent by Stripe.static booleanverifyHeader(String payload, String sigHeader, String secret, long tolerance, Clock clock) Verifies the authenticity (and recency) of a webhook, throwing aSignatureVerificationExceptionif there's a mismatch.
-
Field Details
-
EXPECTED_SCHEME
- See Also:
-
-
Constructor Details
-
Signature
public Signature()
-
-
Method Details
-
verifyHeader
public static boolean verifyHeader(String payload, String sigHeader, String secret, long tolerance) throws SignatureVerificationException Verifies the signature header sent by Stripe. Throws a SignatureVerificationException if the verification fails for any reason.- Parameters:
payload- the payload sent by Stripe.sigHeader- the contents of the signature header sent by Stripe.secret- secret used to generate the signature.tolerance- maximum difference allowed between the header's timestamp and the current time- Throws:
SignatureVerificationException- if the verification fails.
-
verifyHeader
public static boolean verifyHeader(String payload, String sigHeader, String secret, long tolerance, Clock clock) throws SignatureVerificationException Verifies the authenticity (and recency) of a webhook, throwing aSignatureVerificationExceptionif there's a mismatch. Useful for quickly validating incoming webhooks before storing them for later processing (at which time you can use the*WithoutVerificationmethods for parsing).- Parameters:
payload- the payload sent by Stripe.sigHeader- the contents of the signature header sent by Stripe.secret- secret used to generate the signature.tolerance- maximum difference allowed between the header's timestamp and the current timeclock- instance of clock if you want to use custom time instance- Throws:
SignatureVerificationException- if the verification fails.
-
generateSignatureHeader
public static String generateSignatureHeader(String payload, String secret) throws NoSuchAlgorithmException, InvalidKeyException Generates aStripe-Signatureheader for the given payload and secret using the current timestamp.- Parameters:
payload- the payload to sign.secret- the webhook secret.- Returns:
- the generated signature header string.
- Throws:
NoSuchAlgorithmExceptionInvalidKeyException
-
generateSignatureHeader
public static String generateSignatureHeader(String payload, String secret, long timestamp) throws NoSuchAlgorithmException, InvalidKeyException Compute theStripe-Signatureheader for a given webhook body & secret. Useful for signing payloads in unit tests.- Parameters:
payload- the payload to sign.secret- the webhook secret.timestamp- the timestamp to use (seconds since epoch).- Returns:
- the generated signature header string.
- Throws:
NoSuchAlgorithmExceptionInvalidKeyException
-