Encrypt and Decrypt a string variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mathewgk80
    New Member
    • Sep 2007
    • 103

    Encrypt and Decrypt a string variable

    Hi all,

    I have a string variable called userid and i want to encrypt the userid and store it into another variable using the stored procedure. Again i have to decrypt the encrypted value to the original string value using another stored procedure.

    I am using sql server.

    Please help me...

    Thanks and regards,
    Mathew
  • deepuv04
    Recognized Expert New Member
    • Nov 2007
    • 227

    #2
    Originally posted by mathewgk80
    Hi all,

    I have a string variable called userid and i want to encrypt the userid and store it into another variable using the stored procedure. Again i have to decrypt the encrypted value to the original string value using another stored procedure.

    I am using sql server.

    Please help me...

    Thanks and regards,
    Mathew
    In SQL Server 2000, you have to create your own user-defined functions to encrypt the data or use external DLLs to encrypt the data. In SQL Server 2005, these functions and methods are available by default.

    SQL Server 2005 provides the following mechanism of encryption in order to encrypt the data.

    * ENCRYPTION by passphrase
    * ENCRYPTION by symmetric keys
    * ENCRYPTION by Asymmetric keys
    * ENCRYPTION by certificates

    for simplycity you can use ENCRYPTION by passphrase method

    “ENCRYPTION by passphrase” is basically encrypting the data using a password. The data can be decrypted using the same password.

    eg:

    select EncryptByPassPh rase('key', 'abc' )

    result encrypted value: 0x01000000674FB 952B3F9D575EB4B 9E7A22BEC4800F6 310C7F96CA821

    select convert(varchar (100),DecryptBy PassPhrase('key '
    , 0x01000000011FF AE33EA305F8DE68 453A1CE3425C3F6 63849D02F21CE))

    result decrypted value : abc

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Also, you might want to consider this....

      Happy Coding!


      --- CK

      Comment

      Working...