【问题标题】:simple yet secure encrypt / decrypt asp to asp.net简单而安全的加密/解密 asp 到 asp.net
【发布时间】:2011-02-07 15:06:13
【问题描述】:

我有一个登录用户的 ASP/VB6 网络应用程序。我想加密用户身份字段并将其传递(查询字符串)到 asp.net 应用程序,然后对其进行解密以进行数据库查找。

我用谷歌搜索了它并找到了 rot13,尽管它不够安全。我还发现了一些关于 MD5 / RC4 的点击,但没有找到任何好的加密/解密示例。

关于如何实现安全加密/描述逻辑的任何想法?

【问题讨论】:

  • 简单策略:要求通过 SSL 进行登录。

标签: asp.net vb6 asp-classic cryptography encryption


【解决方案1】:

我同意@Brian 的观点 - 不要自己进行加密,在您开始进行密钥管理之前,加密很容易。请使用 SSL/TLS,除非你有一个非常 V.E.R.Y.有充分的理由不这样做。

【讨论】:

    【解决方案2】:

    人们普遍认为,您永远不应解密此类信息,而应将加密与加密进行比较。

    例如,MD5 可以以这种“活板门”方式使用。对信息进行编码,然后存储 MD5 哈希。当您需要进行身份验证时,对新信息进行编码并比较哈希值。未加密的信息永远不会暴露或可用。

    如果这对您的情况不起作用,请查看 Windows Crypto API,它提供了允许全周期加密/解密的替代方案。

    【讨论】:

      【解决方案3】:

      这是一个基本的加密示例。你会想找出你自己的钥匙。我这样做只是为了增加一层复杂性(我希望如此)。正如 Jim 指出的那样,您可以使用它来加密新密码,然后存储结果。在创建密码而不是尝试解密此值(正好相反)之后,您将加密输入的密码并将其与存储的值进行比较。

      'combine these constants to build the encryption key'
      Private Const KEY1 = "abcde"
      Private Const KEY2 = "fghij"
      Private Const KEY3 = "klmno"
      Private Const KEY4 = "pqrst"
      Private Const KEY5 = "uvwxy"
      
      Private Function Encrypt(ByVal s As String, ByVal EncryptionType As  CAPICOM.CAPICOM_ENCODING_TYPE) As String
         Dim oEN As New CAPICOM.EncryptedData
         Dim intENCType As CAPICOM.CAPICOM_ENCRYPTION_ALGORITHM
         Dim strSecret As String
         Dim intTries As Integer
      
         On Error GoTo errEncrypt
      
         intENCType = CAPICOM_ENCRYPTION_ALGORITHM_AES ' try this first and fall back if not supported'
      
         With oEN
      startEncryption:
            .Algorithm = intENCType
            strSecret = KEY2 & KEY5 & KEY4 & KEY1 & KEY3
            .SetSecret strSecret
            strSecret = ""
            .Content = s
            ' the first encryption type needs to be base64 as the .content property'
            ' can loose information if I try to manipulate a binary string'
            .Content = StrReverse(.Encrypt(CAPICOM_ENCODE_BASE64))
            strSecret = KEY1 & KEY4 & KEY3 & KEY2 & KEY5
            .SetSecret strSecret
            strSecret = ""
            Encrypt = .Encrypt(EncryptionType)
         End With
      
         Set oEN = Nothing
      
         Exit Function
      
      errEncrypt:
         If Err.Number = -2138568448 Then
            ' if this is the first time the step the encryption back and try again
            If intTries < 1 Then
               intTries = intTries + 1
               intENCType = CAPICOM_ENCRYPTION_ALGORITHM_3DES
               Resume startEncryption
            End If
         End If
      
         Err.Raise Err.Number, Err.Source & ":Encrypt", Err.Description
         strSecret = ""
         Set oEN = Nothing
      
      End Function
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-31
        • 1970-01-01
        相关资源
        最近更新 更多