Link to home
Start Free TrialLog in
Avatar of Aleks
AleksFlag for United States of America

asked on

Error in function to encrypt

I am getting an error when trying to encrypt data with a function:

Microsoft VBScript runtime  error '800a000d'

Type mismatch: 'getEncryptedStringFromDB'

/bluedot/--tempdecrypt--.asp, line 29


The function is as follow.

 
<script>
 function getEncryptedStringFromDB( str ) {
var cmd = Server.CreateObject("ADODB.Command");
var rs = Server.CreateObject("ADODB.RecordSet");

cmd.ActiveConnection = MM_bluedotjs_STRING;
cmd.CommandText = "dbo.getEncryptedString";
cmd.CommandType = 4;
cmd.CommandTimeout = 0;
cmd.Prepared = true;
cmd.Parameters.Append(cmd.CreateParameter("@LoginId", 3, 1, 4, str));

rs.Open( cmd );

return rs( 0 );

}
 </script>

Open in new window


the field being encrypted is varchar(100)
ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Aleks

ASKER

I changed my code as adviced, attached is the whole page and got this error:

Object required: '' 

/bluedot/--tempdecrypt--.asp, line 47 

Open in new window


This is my code:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html>

<!--#BlueDot Include files-->
<!--#include file="Connections/bluedot.asp" --
 
 
 <script>
 function getEncryptedStringFromDB( str ) {
var cmd = Server.CreateObject("ADODB.Command");
var rs = Server.CreateObject("ADODB.RecordSet");

cmd.ActiveConnection = MM_bluedot_STRING;
cmd.CommandText = "dbo.getEncryptedString";
cmd.CommandType = 4;
cmd.CommandTimeout = 0;
cmd.Prepared = true;
cmd.Parameters.Append(cmd.CreateParameter("@LoginId", 3, 1, 4, str));

Set rs = cmd.Execute;
return rs( 0 );
}
 </script>
 
 

<%
Dim rs_decryptpassword
Dim rs_decryptpassword_cmd
Dim rs_decryptpassword_numRows

Set rs_decryptpassword_cmd = Server.CreateObject ("ADODB.Command")
rs_decryptpassword_cmd.ActiveConnection = MM_bluedot_STRING
rs_decryptpassword_cmd.CommandText = "select UserLoginId, LoginId, password from UserLogin where UserId = 1713" 
rs_decryptpassword_cmd.Prepared = true

Set rs_decryptpassword = rs_decryptpassword_cmd.Execute
rs_decryptpassword_numRows = 0
%>
<!--#BeginBlock-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<p>username:<%=(rs_decryptpassword.Fields.Item("LoginId").Value)%></p>
<p>password: <%=Encryptvb(rs_decryptpassword.Fields.Item("LoginId").Value)%></p>
<p>password decrypted : <%=(rs_decryptpassword.Fields.Item("LoginId").Value)%></p>
</body>
</html>
<%
rs_decryptpassword.Close()
Set rs_decryptpassword = Nothing
%>

Open in new window


This is for an ASP VBScript page.
Avatar of Aleks

ASKER

So .. this is my code:

<p>password decrypted : <%=Encryptvb(rs_decryptpassword.Fields.Item("LoginId").Value)%></p>

Open in new window


This is the function:

   <script>
 function Encryptvb( str ) {
var cmd = Server.CreateObject("ADODB.Command");
var rs = Server.CreateObject("ADODB.RecordSet");

cmd.ActiveConnection = MM_bluedot_STRING;
cmd.CommandText = "dbo.getDecryptedString";
cmd.CommandType = 4;
cmd.CommandTimeout = 0;
cmd.Prepared = true;
cmd.Parameters.Append(cmd.CreateParameter("@LoginId", 3, 1, 4, str));

rs.Open( cmd );

return rs( 0 );

}
 </script>

Open in new window


And yes, it is a StoredProcedure (see below). This is the code to create it.

USE [BlueDot]
GO

/****** Object:  StoredProcedure [dbo].[getEncryptedString]    Script Date: 11/18/2015 15:26:43 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[getEncryptedString] 
	@LoginId varchar(max)
as begin

/*	create master key encryption by password ='mystrongpassword';

	create certificate bluedot with subject = 'bluedot';

	create symmetric key bdotpassword with algorithm=triple_des encryption by certificate bluedot;
*/
	exec OpenKeys;
	
	declare @result varbinary( 256 );
	set @result = dbo.Encryptbdot( @LoginId );
	
	select @result;
	
end
GO

Open in new window