Sample code for 30+ languages & platforms
SQL Server

Get the JWS Payload into BinData

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.GetPayloadBd, which writes the payload of a loaded JWS as raw bytes into a BinData.

Background. This is used when the payload is binary. In practice, validate the signature before trusting the payload.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 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 raw bytes into a BinData.
    DECLARE @bdPayload int
    EXEC @hr = sp_OACreate 'Chilkat.BinData', @bdPayload OUT

    EXEC sp_OAMethod @jws, 'GetPayloadBd', @success OUT, @bdPayload
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @jws, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @jws
        EXEC @hr = sp_OADestroy @bdPayload
        RETURN
      END

    EXEC sp_OAGetProperty @bdPayload, 'NumBytes', @iTmp0 OUT

    PRINT 'Payload is ' + @iTmp0 + ' bytes.'

    EXEC @hr = sp_OADestroy @jws
    EXEC @hr = sp_OADestroy @bdPayload


END
GO