title: How to use DECRYPTBYPASSPHRASE with an Int Column
body: <p>I am trying to use EncryptByPassPhrase and DecryptByPassPhrase to persist an int value in a SQL database.</p>
  
  <p>I have 2 original columns (only for testing, I will remove them once this code is working), Base (varchar) and NextIndex (int). I am encrypting their values into 2 varbinary columns like this:</p>
  
  <pre><code>DECLARE @PassphraseEnteredByUser nvarchar(128);
  SET @PassphraseEnteredByUser = 'some password';
  
  UPDATE [dbo].[Licenses]
  SET EBase = EncryptByPassPhrase(@PassphraseEnteredByUser, Base),
      ENextIndex = EncryptByPassPhrase(@PassphraseEnteredByUser, CONVERT(varchar(10), NextIndex);
  GO
  </code></pre>
  
  <p>Then I am trying to retrieve the values using the DECRYPTBYPASSPHRASE stored procedure:</p>
  
  <pre><code>DECLARE @PassphraseEnteredByUser nvarchar(128);
  SET @PassphraseEnteredByUser = 'some password';
  
  SELECT TOP 1000 [Id]
        ,[Base]
        ,[NextIndex]
        ,CONVERT(varchar, DECRYPTBYPASSPHRASE(@PassphraseEnteredByUser, EBase)) as DEBase
        ,CONVERT(int, DECRYPTBYPASSPHRASE(@PassphraseEnteredByUser, ENextIndex)) as DENextIndex
    FROM [dbo].[Licenses]
  </code></pre>
  
  <p>The string columns (Base) is decrypted correctly, but the integer columns is not: an original value of 1 is decrypted as 49, as value of 2 is decrypted as 50, etc.</p>
  
  <p>I suspect my datatypes for my conversion routines are incorrect, but I cannot figure out how to fix it.</p>