SQL Server
SQL Server
Get the JWS Payload into a StringBuilder
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.GetPayloadSb, which writes the payload of a loaded JWS as text into a StringBuilder, decoded using the given charset.
Background. In practice, validate the signature before trusting the payload.
Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @success int
SELECT @success = 0
DECLARE @jws int
EXEC @hr = sp_OACreate 'Chilkat.Jws', @jws OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Load the JWS compact serialization.
DECLARE @jwsCompact nvarchar(4000)
SELECT @jwsCompact = 'eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>'
EXEC sp_OAMethod @jws, 'LoadJws', @success OUT, @jwsCompact
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @jws, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @jws
RETURN
END
-- Get the JWS payload as text into a StringBuilder, decoded using the given charset.
DECLARE @sbPayload int
EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbPayload OUT
EXEC sp_OAMethod @jws, 'GetPayloadSb', @success OUT, 'utf-8', @sbPayload
IF @success = 0
BEGIN
EXEC sp_OAGetProperty @jws, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @jws
EXEC @hr = sp_OADestroy @sbPayload
RETURN
END
EXEC sp_OAMethod @sbPayload, 'GetAsString', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @jws
EXEC @hr = sp_OADestroy @sbPayload
END
GO