database connection string encryption and decryption

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default database connection string encryption and decryption

    Hi

    I want to encrypt the database connection string and add it to web.config
    file. Before connecting to the database I want to decrypt it.

    Can anyone suggest me how to implement this (c#)

    Regards,

    Reddy


    Srinivasa Reddy K Ganji Guest

  2. Similar Questions and Discussions

    1. SecurityHandler automatic decryption encryption
      hello, i'm writing a plug-in based on SecurityHandler code sample, provided in Adobe SDK version 8. I've to create functions that: 1)...
    2. encryption and decryption using SoapExtension
      Hello. After reading: http://www.xmlforasp.net/codeSection.aspx?csID=72, I have made a web service call, that encrypts specific fields in soap...
    3. encryption/decryption of xml file
      Hi I'm using xml to store the questions and answers for the quiz I'm building. could anybody let me know of any effective encryption method i can...
    4. Encryption / Decryption
      I need to store 3 strings and be able to decrypt them. Does anyone have a link to a E/D routine they can pass on Don.
    5. Decryption/Encryption Error
      2003-07-05 23:52:23 04:52:23 Error IUCTL Digital Signatures on file C:\Program Files\WindowsUpdate\V4\temp\iuident.cab are not trusted...
  3. #2

    Default database connection string encryption and decryption

    Give this a whirl:

    'Retrieve a connection to the database
    Public Shared Function Get_Connection() As
    System.Data.SqlClient.SqlConnection

    Get_Connection = New
    System.Data.SqlClient.SqlConnection()
    Get_Connection.ConnectionString = Decrypt
    (System.Configuration.ConfigurationSettings.AppSet tings
    (CONNECTION_STRING))
    Get_Connection.Open()

    End Function

    Public Shared Function Encrypt(ByVal Clear_Text As
    String) As String

    'Encrypt the text
    Encrypt = Convert.ToBase64String(Transform
    (System.Text.Encoding.Default.GetBytes(Clear_Text) ,
    Get_Encryption_Engine().CreateEncryptor))

    End Function

    Public Shared Function Decrypt(ByVal Cipher_Text As
    String) As String

    'Decrypt the text
    Decrypt = System.Text.Encoding.Default.GetString
    (Transform(Convert.FromBase64String(Cipher_Text),
    Get_Encryption_Engine().CreateDecryptor))

    End Function

    Private Shared Function Get_Encryption_Engine() As
    System.Security.Cryptography.SymmetricAlgorithm

    'Setup the cryptographic service to use
    Get_Encryption_Engine = New
    System.Security.Cryptography.RijndaelManaged()
    Get_Encryption_Engine.Mode =
    System.Security.Cryptography.CipherMode.CBC
    Get_Encryption_Engine.Key =
    Convert.FromBase64String
    ("U1fknVDCPQWERTYGZfRqvAYCK7gFpUukYKOqsCuN8XU=" )
    Get_Encryption_Engine.IV =
    Convert.FromBase64String("vEQWERTYRMrovjV+NXos5g== ")

    End Function

    Private Shared Function Transform(ByVal Source() As
    Byte, ByVal Transformer As
    System.Security.Cryptography.ICryptoTransform) As Byte()

    'Transform the source
    Dim stream As New System.IO.MemoryStream()
    Dim cryptographic_stream As
    System.Security.Cryptography.CryptoStream = New
    System.Security.Cryptography.CryptoStream(stream,
    Transformer,
    System.Security.Cryptography.CryptoStreamMode.Writ e)
    cryptographic_stream.Write(Source, 0,
    Source.Length)

    'Flush the buffer and release stream resources
    cryptographic_stream.FlushFinalBlock()
    cryptographic_stream.Close()

    'Return the data
    Transform = stream.ToArray()

    End Function

    HTH,
    Gaz
    >-----Original Message-----
    >Hi
    >
    >I want to encrypt the database connection string and add
    it to web.config
    >file. Before connecting to the database I want to
    decrypt it.
    >
    >Can anyone suggest me how to implement this (c#)
    >
    >Regards,
    >
    >Reddy
    >
    >
    >.
    >
    Gary Varga Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139