Re: SqlServer 2000 sp_OAMethod - WeOnlyDo Discussion board

Re: SqlServer 2000 sp_OAMethod (General questions)

by beto21971, Saturday, August 22, 2009, 01:23 (3011 days ago) @ beto21971

Finally, Fixed:

Correct Line Code:

EXEC @hr =sp_OAMethod @Crypt, 'Encrypt', null,@DecBlob,@EncBlob output

I let you the full code that I proved with 10 encryption algoritms and it work just fine!!!.Enjoy it.

DECLARE @TXT_TO_CRYPT VARCHAR(4000)

SET @TXT_TO_CRYPT='HOLA MUND0'

DECLARE @hr int
DECLARE @src varchar(255), @desc varchar(255)
DECLARE @Largo int
DECLARE @CIFRADO VARCHAR(4000)
/*---------------------------------------------------------------
/ CREA EL OBJETO CRYPT
----------------------------------------------------------------*/
DECLARE @Crypt int
EXEC @hr = sp_OACreate 'WeOnlyDo.wodCryptCom.1', @Crypt OUT,1
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @Crypt, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END


/*---------------------------------------------------------------
/ CREA EL OBJETO DECBLOB
----------------------------------------------------------------*/
DECLARE @DecBlob int
EXEC @hr = sp_OACreate 'WeOnlyDo.MemBlob.1', @DecBlob OUT,1
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @DecBlob, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END

/*---------------------------------------------------------------
/ CREA EL OBJETO ENCBLOB
----------------------------------------------------------------*/
DECLARE @EncBlob int
EXEC @hr = sp_OACreate 'WeOnlyDo.MemBlob.1', @EncBlob OUT,1
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @EncBlob, @src OUT, @desc OUT
SELECT hr=convert(varbinary(4),@hr), Source=@src, Description=@desc
RETURN
END

/*------------------------------------------------
/ SETEA PARAMETROS DE LOS OBJETOS
-------------------------------------------------*/
EXEC sp_OASetProperty @DecBlob, 'Text', 'PRUEBA'
EXEC sp_OASetProperty @Crypt , 'Type', 0 /* DES */
EXEC sp_OASetProperty @Crypt , 'SecretKey', 'WeOnlyDo!'
EXEC sp_OASetProperty @Crypt , 'Mode', 0
EXEC sp_OASetProperty @Crypt , 'Optimized', 0
EXEC @hr =sp_OAMethod @Crypt, 'Encrypt', null,@DecBlob,@EncBlob output
IF @hr <> 0
BEGIN
PRINT 'ERROR METODO ENCRYPT: '+Convert(varchar,@hr)
EXEC sp_OAGetErrorInfo @Crypt
RETURN
END

EXEC @hr = sp_OAGetProperty @EncBlob, 'ToHex', @CIFRADO OUT
IF @hr <> 0
BEGIN
EXEC sp_OAGetErrorInfo @EncBlob
RETURN
END

PRINT 'Cifrado: '+@CIFRADO

exec sp_OADestroy @EncBlob
exec sp_OADestroy @DecBlob
exec sp_OADestroy @Crypt


Complete thread: