CFML动态解密来自数据库的字符串

时间:2013-04-01 08:54:04

标签: sql-server encryption coldfusion cfml

我有以下脚本尝试从我的数据库中选择一些项目并解密加密的项目,问题是加密密钥是唯一的,我在表格中更改了company_id

<cfset request.ek = "password">
<!-- <cfset encKey = encrypt(request.ek, company_id)> -->
<!-- <cfset decrypted = decrypt(urldecode(arguments.mystring), encKey)> -->

<cfquery name="header" datasource="MyDB">
    SELECT TOP 10
        ID,
        company_id,
        encString
    FROM 
        dbo.[TableName];
</cfquery>

<cfoutput>ID|company_id|encString<br></cfoutput>

<cfloop query="header">
    <cfoutput>#ID#|#company_id#|#decrypt(urldecode(encString, encrypt(request.eq, company_id)))#<br></cfoutput>
</cfloop>

我收到此错误:

Parameter validation error for the DECRYPT function.
The function accepts 2 to 6 parameters.

EDIT。 谢谢Scott Stroz,我真的和括号混在一起。我的代码应该是:

<cfset request.ek = "password">
<!-- <cfset encKey = encrypt(request.ek, company_id)> -->
<!-- <cfset decrypted = decrypt(urldecode(arguments.mystring), encKey)> -->

<cfquery name="header" datasource="MyDB">
    SELECT TOP 10
        ID,
        company_id,
        encString
    FROM 
        dbo.[TableName];
</cfquery>

<cfoutput>ID|company_id|encString<br></cfoutput>

<cfloop query="header">
    <cfoutput>#ID#|#company_id#|#decrypt(urldecode(encString), encrypt(request.eq, company_id))#<br></cfoutput>
</cfloop>

1 个答案:

答案 0 :(得分:3)

您在代码示例末尾附近对decrypt()的调用只有1个参数。看起来你的括号可能有问题。

看起来像:

decrypt(urldecode(encString, encrypt(request.eq, company_id)))

可能需要:

decrypt(urldecode(encString), encrypt(request.eq, company_id))

假设

  1. 您在数据库中加密的字符串然后在插入之前进行了url编码。
  2. 您使用密钥{request.eq加密了字符串,密钥为company_id