I can encrypt and decrypt varchar, nvarchar,char columns using symmetric key but cannot do the same on int,datetime,float,bigint data types columns
Sample table: Mytable
| Id Code percentage name activity |
+------------------------------------------+
| 1 ad 43.43 James Running |
| 3 Pr 70.43 Sam Cooking |
| 5 nt 90.34 Lisa Walking |
| 4 ash 0.00 James Stealing |
| 2 han 0.00 James Lacking |
| 8 ant 73 Sam Cooking |
I want to encrypt and decrypt ID column and Percentage which are of integer and float data types respectively.
I am using this code to encrypt:
OPEN SYMMETRIC KEY SymKey DECRYPTION BY CERTIFICATE data
ALTER TABLE Mytable
SET ADD idencry VARBINARY(128) NULL
UPDATE Mytable
SET idencry = ENCRYPTBYKEY(KEY_GUID('datamSymKey'), CONVERT(varbinary, ID))
To decrypt I am using this code:
SELECT
id,
CONVERT(NVARCHAR(60), DECRYPTBYKEY(idencry )), *
FROM
Mytable
But its not returning the correct result... same goes with float and datetime date type