(SQL Server) Decode Base64
Demonstrates how to decode base64.
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @bd int
-- Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0
EXEC @hr = sp_OACreate 'Chilkat.BinData', @bd OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
-- Append a base64 string to bd.
DECLARE @success int
EXEC sp_OAMethod @bd, 'AppendEncoded', @success OUT, 'c2VjcmV0', 'base64'
-- The bd now contains the decoded bytes.
-- Let's say it was a password string..
DECLARE @password nvarchar(4000)
EXEC sp_OAMethod @bd, 'GetString', @password OUT, 'utf-8'
-- Decodes to "secret".
PRINT 'password = ' + @password
EXEC @hr = sp_OADestroy @bd
END
GO
|