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)
LVL 1
AleksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
what is "dbo.getEncryptedString" ? Is it a stored procedure?
If so, please try the following:
<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));

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

Open in new window


HTH
Rainer
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
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.
0
AleksAuthor Commented:
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

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.