To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Go Back   ASP Message Board > ASP Technology > Advanced ASP

Advanced ASP This forum is for advanced ASP questions. If you have not received a response from the General ASP Q&A forum, try posting your question here.

Reply
 
Thread Tools Display Modes
  #1  
Old 02-02-2010, 10:09 AM
NickZombie NickZombie is offline
Junior Member
 
Join Date: Dec 2009
Posts: 10
Default Classic ASP & VB.Net 2008 Crypto DLL

Hiya Guys,

The VB.Netters will all be letting out a collective sigh at this one, while Classic ASP developers may be quite interested.

I'm working on a project with sensitive data stored in a database, for similar projects I would use RC4 two way encryption from a script similar to this one to securely encrypt and decrypt the data using a password that I can specify.

The trouble is, I'm also working on a VB.Net 2008 application to read some of this data, which is incompatible with .Net 3.5 - Not the idea solution, one old Class ASP function writing to the database with one encryption method/function, reading it with another. You can imagine the problems associated with this, lots of data encrpted that can't be read!!


What I've done so far with my limited but quickly expanding (three weeks lol) experiance of VB.Net 2008 Express Edition is to try and make a DLL that I could register on the server, that both Classic ASP and my VB.Net Desktop Application can both use as a shared function.

First of all, is this the right way around of doing things, or am I missing a blinder here?

Secondly, I've done so much research on Google (and Yahoo frustratingly!) on creating a .Net 3.5 DLL that classic asp can use, the only links that were half useful related to earlier versions of the program (6.0), and much of the information/instructions/menu locations can't be found in the latest Express version.


Creating the DLL, I tried following this example, but couldnt find the modern equivalent for 'Apartment Threaded', and the section 'Now let us add the reference Library. Open the Project -> Preferences, then select Active server Pages Object Library from the List of References appearing' just left me bewildered, I couldn't find that from the list of COM objects avaliable to reference, is it still required in 3.5?

The simple function I created to test if Classic ASP can talk to the DLL is as follows:

Code:
Public TestString As String

Function MakeTest(TestString)
MakeTest = TestString
End Function

So, in my Class ASP page, if I call the following code, it should output the same as it gets inputted:

Code:
Set foo = Server.CreateObject("myDllName.myDllForm")
bar = foo.MakeTest("It_Lives!")

On a seperate but linked matter, when I tried to regsvr32 my dll it says it couldnt find an entry point.. I guessed this was related to something missing/wrong in the code?

Help! What have I missed out?
Reply With Quote
  #2  
Old 02-02-2010, 10:11 AM
NickZombie NickZombie is offline
Junior Member
 
Join Date: Dec 2009
Posts: 10
Default

Quote:
The trouble is, I'm also working on a VB.Net 2008 application to read some of this data, which is incompatible with .Net 3.5
Sorry, Classic ASP istead of 3.5 there! Multithreading error in my head
Reply With Quote
  #3  
Old 02-02-2010, 06:46 PM
TheFinalizer TheFinalizer is offline
Senior Member
 
Join Date: Sep 2008
Posts: 416
Default

regsvr32 is for Win32 libraries...You want to use regasm to register your managed (.Net) assembly. More info here: http://msdn.microsoft.com/en-us/libr...w6(VS.80).aspx
Reply With Quote
  #4  
Old 02-03-2010, 05:50 AM
NickZombie NickZombie is offline
Junior Member
 
Join Date: Dec 2009
Posts: 10
Default

Thanks for the link, since I posted this message, I've decided to ditch this idea and use CAPICOM instead, it does the same functions as what I wanted to create with my DLL, so it saves re-inventing the wheel!

Files for interest:

CAPICOM contains all of the functions you'll ever need for two way encryption. It's a free download from Microsoft, and you can access it in Classic ASP as well as .Net 3.5. You can download it here: http://www.microsoft.com/downloads/d...displaylang=en

To Use CAPICOM in Classic ASP:

Code:
Const CAPICOM_SHA1 = 0        
Const CAPICOM_MAXIMUM = 0
Const CAPICOM_3DES = 3

Function DoEncrypt(encrval, Algorithm, KeyLength, Password)
Dim EncryptedData
Set EncryptedData = CreateObject("CAPICOM.EncryptedData")
EncryptedData.Algorithm.Name = Algorithm
EncryptedData.Algorithm.KeyLength = KeyLength
EncryptedData.SetSecret Password
EncryptedData.Content = encrval
DoEncrypt = EncryptedData.Encrypt
Set EncryptedData = Nothing
End Function

function DecryptMessage(encrypted, Password)
Dim EncryptedData
Set EncryptedData = CreateObject("CAPICOM.EncryptedData")
EncryptedData.Algorithm.Name = Algorithm
EncryptedData.Algorithm.KeyLength = KeyLength
EncryptedData.SetSecret Password
EncryptedData.Decrypt encrypted
DecryptMessage = EncryptedData.Content
Set EncryptedData = Nothing
end function


testStr = "This is the string to encode"
encryptedText = DoEncrypt(testStr,CAPICOM_3DES,CAPICOM_MAXIMUM,"1234567")
response.Write(encryptedText)
response.Write("<br />")
response.Write(DecryptMessage(encryptedText,"1234567"))
and the vb.net code to encrypt/decrypt is:

Code:
Public Class Form1

    Const CAPICOM_SHA1 = 0
    Const CAPICOM_MAXIMUM = 0
    Const CAPICOM_3DES = 3


    Public Function DoEncrypt(ByVal encrval, ByVal Algorithm, ByVal KeyLength, ByVal Password)
        Dim EncryptedData
        EncryptedData = CreateObject("CAPICOM.EncryptedData")
        EncryptedData.Algorithm.Name = Algorithm
        EncryptedData.Algorithm.KeyLength = KeyLength
        EncryptedData.SetSecret(Password)
        EncryptedData.Content = encrval
        DoEncrypt = EncryptedData.Encrypt
        EncryptedData = Nothing
    End Function




    Public Function DecryptMessage(ByVal encrypted, ByVal Password)
        Dim EncryptedData
        EncryptedData = CreateObject("CAPICOM.EncryptedData")
        EncryptedData.Algorithm.Name = CAPICOM_3DES
        EncryptedData.Algorithm.KeyLength = CAPICOM_MAXIMUM
        EncryptedData.SetSecret(Password)
        EncryptedData.Decrypt(encrypted)
        DecryptMessage = EncryptedData.Content
        EncryptedData = Nothing
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox2.Text = DecryptMessage(TextBox1.Text, "1234567")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = DoEncrypt(TextBox2.Text, CAPICOM_3DES, CAPICOM_MAXIMUM, "1234567")
    End Sub

End Class
(assuming you have two buttons labeled Button1 and Button2, as well as two textboxes, TextBox1 and TextBox2....

Problem sorted, I hope this helps someone else in the same position!
Nick
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:56 PM.

More ASP Resources

Reference:
-- ASPFAQs.com
-- VBScript Reference
-- JScript Reference
-- SQL Books Online
-- Official Docs
-- Commonly Asked Messageboard Questions

Resources:
-- Recent ASP Articles
-- ASP.NET Information
-- 4Guys ASP F.A.Q.
-- ASPFAQs.com
-- ASP Internet Resource
-- ASP.NET Internet Resource
-- ASP Coding Tips
-- Newsletter
-- Related Web Technologies
-- User Tips!!
-- ASP-related ListServs

Information:
-- Advertise
-- Author an Article
-- Feedback
-- ASP Messageboard F.A.Q.

Windows Technology
Check out these Web sites for articles, tutorials, FAQs, and code on ASP and related technologies!
-- 15Seconds.com
-- ASP101.com
-- ASPFAQs.com
-- ASPMessageboard.com
-- ASPWire.com

[Complete List of Sites]




Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.