homebrew01 (4/5/2010)
Will BlowFish or TwoFish work with image data ?? I downloaded the latest SQL toolkit and Tried running TwoFish after modifying it to handle image data converted to varbinary(max). The data came back as NULL, instead of encrypted. Either I did something wrong (very likely), or there's some limitation in the DLL for length, or there's some other problem I don't understand.
--modified fn_encrypt_twofish in the hopes it will work with bigger data
CREATE FUNCTION [dbo].[fn_encrypt_twofish_max] (@plaintext VARBINARY(max),
@localkeyname VARCHAR(128),
@password VARCHAR(128),
@keybits INT)
RETURNS VARBINARY(max)
AS
BEGIN
DECLARE @masterkey VARBINARY(64)
DECLARE @localkey VARBINARY(80)
SELECT @masterkey = m.[Key], @localkey = l.[Key]
FROM dbo.Local_Key_Vault l, dbo.Master_Key_Vault m
WHERE l.[name] = @localkeyname
AND l.[master_key_name] = m.[name]
DECLARE @enctext VARBINARY(max)
EXEC dbo.xp_encrypt_twofish @plaintext, @enctext OUTPUT, @password, @masterkey, @localkey, @keybits
RETURN @enctext
END
and then ran
-- Encrypt data
UPDATE MyTable
SET VoiceData = cast(master.dbo.fn_encrypt_twofish_max(VoiceData ,
'Local Key 1', NULL, 32) AS VARBINARY(max))
Thoughts ?
TIA
Hi HomeBrew,
This was written originally for SQL 2000, and the XP's would not accept BLOB data. You're limited to a max. of 8,000 bytes in most cases (I believe the Blowfish implementation maxxed out at 2,000 bytes). You're using SQL 2005 or 2008 (otherwise you wouldn't have access to varbinary(max)). If you're interested contact me offline and I'll send you an updated version of Blowfish/Twofish that uses CLR and doesn't have these same limitations.
Thanks
Mike C