Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Encryption CC Number

Status
Not open for further replies.

mcauliff

Programmer
Feb 26, 2007
71
US
Using SQL Server 2005 Symmetric key to encrypt the credit cardnumber. All setup steps have been completed. I have tested using SQL query and verified that the encryption works.

In the program (VBScript); I coded this statement;
rsOrderHeader("cc_number_encrypt") = EncryptByKey(Key_GUID("MosasKey"), Trim(Request("cc_number")))


cc_number_encrpyt is defined as varbinary(256)

I'm getting an error; "Type mismatch: 'Key_GUID' "

what is wrong with the statement?
 
it looks like Key_Guid is a function, to which you are passing a string.

Does Key_Guid accept strings?

On top of that does the encryptByKey function take, as the first parameter, whatever key_guid returns?

When a multi-function line like that doesn't work perfect the first time, I break it out into steps.

(WAIT A MINUTE)
I really hope that is in a session or a form value and not the querystring.


Dim strKey
strKey = Key_Guid
Response.write(strKey)
EncryptByKey(strKey, Trim(Request("cc_number")))



If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
I have corrected the coding error, but now the SQL Server 2005 encryption function does not encrypt the data.

Here is the code

SQLQuery = "Open SYMMETRIC KEY MosasKey decryption by certificate MosasCertificate"
Connection.Execute(SQLQuery)
If err.number <> 0 then
Response.Write("<br>error occured on Open symmetric key")
Response.Write("<br>error is " & err.number)
Response.End
Else
Response.Write("MosasKey is Opened<br>")
Response.Flush
End If


strCCNumber = Trim(Request("cc_number"))

Response.Write("<BR>Value of strCCNumber is " & strCCNumber)
Response.Flush


SQLQuery = "Update order_header set cc_number_encrypt = EncryptByKey(Key_GUID('MosasKey'), '" & strCCNumber & "') where order_id = " & ordernum
Response.Write("<br>Value of SQL is " & SQLQuery & "<BR>")
Response.Flush
Connection.Execute SQLQuery

If err.number <> 0 Then
Response.Write("<br>Error in Encrypt Update")
Response.Write("<br> err.number is " & err.number)
Response.End
End If


Here are the displays

Prior to Encrypt logicMosasKey is Opened

Value of strCCNumber is 123456789012
Value of SQL is Update order_header set cc_number_encrypt = EncryptByKey(Key_GUID('MosasKey'), '123456789012') where order_id = 151759


What is missing? when I view the table the cc_number_encrypt is NULL.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top