ASP MagicCrypt Component  

  The growth of the Internet and E-commerce are driving a need for increased security and encryption.
  MagicCrypt provides you with easy access to and simple integration with several cryptography technologies. MagicCrypt itself does not implement any new algorithms and technologies. Instead, it works with already implemented technologies within Cryptography Service Providers (CSPs) provided with Windows NT. MagicCrypt supplies you with an easy-to-use, intuitive interface to those cryptography provider functions to be used in ASP, VB and VC++. Works with Windows NT and Windows 9x.

If you try to use MagicCrypt under IIS5 with Application protection medium or high you will fail. That is because of permissions of the code. Most probably that you code will be run under IWAM_<HOSTNAME> user and this user has no permissions to connect Cryptographic Service Providers and so MagicCrypt component doesn't work. The solution is to run MagicCrypt code under other user. MagicService component enable to run MagicCrypt under any user you want.

Key features of MagicCrypt, include:

  • String encoding/decoding
  • Files encoding/decoding
  • String Hashing
  • MIME format converting

The MagicCrypt object contains two classes:

  • SingleKey Class: it uses a single key (or sometimes referred as session key), is used to encrypt/decrypt data with what we call a password. The string or file could be encrypted using another string (password) and later could be decrypted by applying the same password. Password could be imported and exported from and to a file.
  • DoubleKey Class: it uses what is called Public-Private Key Pairs to perform encryption/decryption operations. Usually file would be encrypted using public key and then decrypted when needed using a private key. Public key also could be exported and saved to a file.
(A few of the functions are shared by both classes. HastString performs the same operations if it is called from SingleKey or DoubleKey class.)

NOTE:
By default MagicCrypt will point to "Microsoft Base Cryptographic Provider v1.0" to provide it services. However you have an option to work with any provider, as long as it is provided by your Windows NT.

Evaluation of MagicCrypt Component
Click here to download a 30-days evaluation copy of MagicCrypt Component.

Purchasing MagicCrypt Component
You can get MagicCrypt online or by phone from The Registration Network

Also, you may order by sending check to: Dana Consulting Inc.
(in the memo field specify MagicCrypt)

Send it to:
Dana Consulting Inc.
14936 CreditView Drive
Savage, MN 55378

Please, print, fill out and enclose Order Form located in OrderForm.html file

Installation

  • To register MagicCrypt component move the MagicCrypt.dll, register.exe and register.bat into a subdirectory. To register the component on the system change to the directory where you installed the DLL and run Register.bat. It will give you a message saying that your component was registered. You can start using the component for 30-day evaluation trial.

 
top
 

Working with MagicCrypt

SingleKey     DoubleKey

SingleKey Class Methods
 
DecodeFile
DecodeMIMEFile
DecodeString
EncodeFile
EncodeMIMEFile
EncodeString
GenerateRandomKey
GetKey
GetLastErrorDSCR
GetLastErrorNbr
GetProviderInfo
HashString
OpenKey
Reset
SaveKey
SetAlg
SetHashAlg
SetKey
SetProvider
 
Examples
 

 

  DecodeFile Function
Method of SingleKey class.

Example

Decodes and decrypts the encoded file using the single key(the same key that file was encoded with) and saves the decoded file; returns an integer indicating weather file was decoded successfully -1 or failed 0.

Syntax
DecodeFile(strDestFile As String, strSourceFile As String) As Long
StrDestFile Required. String expression that specifies a file name where encoded file will be decoded to; may include directory or folder, and drive.
StrSourceFile Required. String expression that specifies a file name of the file to be decoded; may include directory or folder, and drive.
 

  DecodeString Function
Method of SingleKey class.

Example

Decodes the encoded user-defined string using the single key (the same key that string was encoded with); returns an integer indicating weather file was decoded successfully -1 or failed 0.

Syntax
DecodeString(strSource As String) As String
strSource Required. String expression for the encoded string
 

  GenerateRandomKey Function
Method of SingleKey class.

Example

Generates random key, saves key to the file and returns an integer indicating whether key generated successfully -1 or failed 0.

Syntax
GenerateRandomKey(strFile As String) As Long
StrFile Required. String expression that specifies a file name where single key to be saved; may include directory or folder, and drive.
 

  EncodeFile Function
Method of SingleKey class.

Example

Encodes the file into binary format and saves the encoded file using the single key; returns an integer indicating whether file was encoded successfully -1 or failed 0.
Note:you do not have to set a key to encode a file, a random key will be generated so you can save it and open for decoding.

Syntax
EncodeFile(strDestFile As String, strSourceFile As String) As Long
StrDestFile Required. String expression that specifies a file name where encoded file will be saved to; may include directory or folder, and drive.
StrSourceFile Required. String expression that specifies a file name of the file to be encoded; may include directory or folder, and drive.
 

  EncodeString Function
Method of SingleKey class.

Example

Encodes the user-defined string using the single key; returns an integer indicating whether string was encoded successfully -1 or failed 0.
Note:you do not have to set a key to encode a user-defined string, a random key will be generated, so you can save it and open for decoding.

Syntax
EncodeString(strSource As String) As String
strSource Required. String expression that needs to be encoded.
 

  HashString Function
Method of SingleKey class.

Example

Hashes the given string (one way hashing). Then you can only compare hashes of this string and another. Function returns hash value of the given string.
Note:you do not have to set any key to hash the string.

Syntax
HashString(strIn As String) As String
strln Required. String expression that needs to be hashed.
 

  OpenKey Function
Method of SingleKey class.

Example

Reads the single key from the file, StrKeyFile; returns an integer indicating whether key was opened successfully -1 or failed 0.

Syntax
OpenKey(StrKeyFile As String) As StringKey
StrKeyFile Required. File name where the key value was saved.
 

  SaveKey Function
Method of SingleKey class.

Example

Saves key to the file and returns an integer indicating whether key saved successfully -1 or failed 0.

Syntax
SaveKey(strFile As String) As Long
StrFile Required. String expression that specifies a file name where single key to be saved; may include directory or folder, and drive.
 

  SetAlg Function
Method of SingleKey class, DoubleKey class.

Example

This method sets different cryptographic algorithms that are supported by Cryptographic Providers. Parameter required is of type: ALG_ID (list of ALG_ID   values).
Returns an integer indicating whether algorithm was set successfully -1 or failed 0.

Syntax
SetAlg (lALg) As Long
 

  SetHashAlg Function
Method of SingleKey class, DoubleKey class.

Example

This method sets different hashing algorithms that are supported by Cryptographic Providers. Parameter required is of type: ALG_ID (list of ALG_ID   values).
Returns an integer indicating whether algorithm was set successfully -1 or failed 0.

Syntax
SetHashAlg (lALg) As Long
 

  SetKey Function
Method of SingleKey class.

Example

Sets a user-defined single key and returns an integer indicating whether key was set successfully -1 or failed 0.

Syntax
SetKey(strKey As String) As Long
StrKey Required. String expression that is used as unique identifier for single key object, session key.
 

  GetKey Function
Method of SingleKey class.

Example

Retrieves a current single key value that was set. This method returns a value only if key was set through SetKey method and still in memory. It will not retrieve any value if key was set using OpenKey or GenerateRandomKey methods.

Syntax
GetKey() As String
 

  Reset Function
Method of SingleKey, DoubleKey classes.

Example

Resets a single key. To decode that document(file or string) you have to set the same key back, otherwise you will not be able to decode the document; returns an integer indicating whether key was reset successfully -1 or failed 0.

Syntax
Reset() As Long
 

  GetProviderInfo Function
Method of SingleKey, DoubleKey classes.

Example

Returns provider information as string. For more information about providers, see SetProvider method.
Default provider is Microsoft Base Cryptographic Provider v1.0

Syntax
GetProviderInfo () As String
 
top
  SetProvider Function
Method of SingleKey, DoubleKey classes.

Example

Sets a provider information. List of provider names may be found in the registry:
HKEY_LOCAL_MACHINE
    SOFTWARE
    Microsoft
                Cryptography
                                Defaults
                                            Provider

Syntax
SetProvider(strProvName As String) As Long
strProvName Required. String expression &ndash; name of the provider.
Example of available Microsoft provider&rsquo;s names:
  • Microsoft Base Cryptographic Provider v1.0
  • Microsoft Base DSS and Diffie-Hellman Cryptographic Provider
  • Microsoft Base DSS Cryptographic Provider
  • Microsoft Enhanced Cryptographic Provider v1.0
Microsoft Base Cryptographic Provider v1.0 is default provider.
 

  GetLastErrorDSCR Function
Method of SingleKey, DoubleKey classes.

Example

Returns last error description.

Syntax
GetLastErrorDSCR() As String
 

  GetLastErrorNbr Function
Method of SingleKey, DoubleKey classes.

Example

Returns last error number.

Syntax
GetLastErrorNbr() As Long
 

  DecodeMIMEFile Function
Method of SingleKey class.

Example

Decodes the file from MIME format and saves the file; returns an integer indicating whether file was encoded successfully -1 or failed 0. This method is used when converting file from MIME format to binary format. Since this method does not perform any decryption of the file, only decoding, no key needs to be set for this method.

Syntax
DecodeMIMEFile(strDestFile As String, strSourceFile As String) As Long
StrDestFile Required. String expression that specifies a file name where encoded file will be decoded to; may include directory or folder, and drive.
StrSourceFile Required. String expression that specifies a file name of the file to be decoded; may include directory or folder, and drive.
 

  EncodeMIMEFile Function
Method of SingleKey class.

Example

Encodes the file to MIME format and saves the file; returns an integer indicating whether file was encoded successfully -1 or failed 0. This method is used when converting file from binary format to MIME format. Since this method does not perform any encryption of the file, only encoding, no key needs to be set for this method.

Syntax
EncodeMIMEFile(strDestFile As String, strSourceFile As String) As Long
StrDestFile Required. String expression that specifies a file name where encoded file will be saved to; may include directory or folder, and drive.
StrSourceFile Required. String expression that specifies a file name of the file to be encoded; may include directory or folder, and drive.
 

  Calling MagicCrypt Object from VB for SingleKey class

To call the MagicCrypt Object to use single key methods from Visual Basic, you will need to include the MagicCrypt.Dll in the references and create the object using the following code:

Dim MyObject as MagicCryptLib.SingleKey
Set MyObject = New MagicCryptLib.SingleKey
To call the MagicCrypt Object to use single key methods from Active Server Pages, you may want to include the MagicCrypt.Dll in the references and create the object using the following code:
Set MyObject = Server.CreateObject("MagicCrypt.SingleKey")

 

  Set Key, Encode/Decode a user-defined string using SingleKey class

This example demonstrates how to use methods of a SingleKey class, in particular how to set a key and encode/decode a user-defined string:SetKey, DecodeString, EncodeString, SaveKey methods.

Set MyObject = Server.CreateObject("MagicCrypt.SingleKey")
 
MyKey = "Mypassword"
'Setting Single Key
MyObject.SetKey MyKey
Response.Write ("Key: "& MyObject.GetKey &"<br>")
 
'Encode string
Mystr = "My String to Encode"
enMystr = MyObject.EncodeString(Mystr)
MyObject.SaveKey "MyKey.txt"
MyObject.Reset 'Resetting single key
MyObject.SetKey MyKey
Response.Write ("Decoded string: " & MyObject.DecodeString(enMystr))
MyObject.SaveKey "MyKey.txt"

 

  Encode/Decode a file, Generate Random key using SingleKey class

This example demonstrates how to use methods of a SingleKey class, in particular how to encode/decode file:
GenerateRandomKey, DecodeFile, EncodeFile, OpenKey methods

Set MyObject = Server.CreateObject("MagicCrypt.SingleKey")
 
MyObject.GenerateRandomKey "MyKey.txt"
'Encode File
MyObject.EncodeFile "EncodeFile.txt", "Myfile.txt"
MyObject.Reset
'Opening Saved Randomly generated key
MyObject.OpenKey "MyKey.txt"
'Decode string
MyObject.DecodeFile "DecodeFile.txt", "EncodeFile.txt"

 

  Hash a string using SingleKey class

This example demonstrates how to perform one-way hashing using methods of a SingleKey class.

Set MyObject = Server.CreateObject("MagicCrypt.SingleKey")
 
str1 = "1 String to Hash"
str2 = "2 String to Hash"
'Hash string
hstr1 = MyObject.HashString(str1)
Response.Write hstr1
 
hstr2 = MyObject.HashString(str2)
Response.Write hstr2
 
hstr2 = MyObject.HashString(str1)
Response.Write hstr2

 

  Getting Provider Information using SingleKey class

This example demonstrates how to retrieve information about provider and sets different providers using methods of a SingleKey class.
GetProviderInfo,SetProvider methods.

Set MyObject = Server.CreateObject("MagicCrypt.SingleKey")
 
CurrProvider = MyObject.GetProviderInfo
Response.Write CurrProvider
MyObject.SetProvider "Microsoft Base DSS Cryptographic Provider"
CurrProvider = MyObject.GetProviderInfo
Response.Write CurrProvider

 

  Converting file to MIME format using SingleKey class

This example demonstrates how to use methods of SingleKey class, in particular how to convert files from binary format to MIME using EncodeMIMEFile, DecodeMIMEFile methods. First, you encode file to a binary format file, using EncodeFile method, then convert the destination file to MIME format using EncodeMIMEFile method. To decode last file, use DecodeMIMEFile first and then DecodeFile methods.
Note: no key needs to be set for to encode/decode file to and from MIME format.

Set MyObject = Server.CreateObject("MagicCrypt.SingleKey")
 
MyObject.GenerateRandomKey "c:\Crypt\MyKey.txt"
'Encode File to binary format
MyObject.EncodeFile "c:\Crypt\EncodeFile_bin.txt", "c:\Crypt\MyFile.txt"
MyObject.EncodeMIMEFile "c:\Crypt\EncodeFile_MIME.txt", "c:\Crypt\EncodeFile_bin.txt"
MyObject.Reset
MyObject.DecodeMIMEFile "c:\Crypt\DecodeFile_bin.txt", "c:\Crypt\EncodeFile_MIME.txt"
'Opening key
MyObject.OpenKey "c:\Crypt\MyKey.txt"
'Decode string
MyObject.DecodeFile "c:\Crypt\DecodeFile.txt", "c:\Crypt\DecodeFile_bin.txt"

 

  Setting different Cryptographic Algorithms using SingleKey, DoubleKey classes

This example demonstrates how to set Algorithms supported by Cryptographic Providers Parameter required for SetAlg method is of type: ALG_ID (List of ALG_ID   values).

Set MyObject = Server.CreateObject("MagicCrypt.SingleKey")
'RC2,RC4 encryption algorithms
CALG_RC2=26114
CALG_RC4=26625
MyObject.SetProvider "Microsoft Enhanced Cryptographic Provider v1.0"
MyObject.SetAlg CALG_MD5

 
top

 
 

DoubleKey Class Methods
 
DecodeFile
EncodeFile
GenerateExchangeKeyPair
GetLastErrorDSCR
GetLastErrorNbr
Reset
GetProviderInfo
HashString
OpenKeyPair
OpenPublicKey
SetAlg
SetHashAlg
SaveKeyPair
SavePublicKey
SetProvide
SetAlg
SetProvider
 
Examples
 

 

  DecodeFile Function
Method of DoubleKey class.

Example

Decodes and decrypts the encoded file using the private key from the key pair, saves the decoded file. To encode the file, it's enough to use only public key from the same key pair; returns an integer indicating whether file was decoded successfully -1 or failed 0.

Syntax
DecodeFile(strDestFile As String, strSourceFile As String) As Long
StrDestFile Required. String expression that specifies a file name where encoded file will be decoded to; may include directory or folder, and drive.
StrSourceFile Required. String expression that specifies a file name of the file to be decoded; may include directory or folder, and drive.
 

  EncodeFile Function
Method of DoubleKey class.

Example

Encodes the file into binary format and saves the encoded file using the public key of the generated key pair; returns an integer indicating whether file was encoded successfully -1 or failed 0.

Syntax
EncodeFile(strDestFile As String, strSourceFile As String) As Long
StrDestFile Required. String expression that specifies a file name where encoded file will be saved to; may include directory or folder, and drive.
StrSourceFile Required. String expression that specifies a file name of the file to be encoded; may include directory or folder, and drive.
 

  GenerateExchangeKeyPair Function
Method of DoubleKey class.

Example

Generates random key pair: private key and public key. Either key pair or public key can be saved and opened; returns an integer indicating whether key pair was generated successfully -1 or failed 0.

Syntax
GenerateRandomKey(strFile As String) As Long
StrFile Required. String expression that specifies a file name where single key to be saved; may include directory or folder, and drive.
 

  SaveKeyPair Function
Method of DoubleKey class.

Example

Saves randomly generated key pair to a file; returns an integer indicating weather key saved successfully -1 or failed 0.

Syntax
SaveKeyPair(strFile As String) As Long
StrFile Required. String expression that specifies a file name where key pair to be saved; may include directory or folder, and drive.
 

  SavePublicKey Function
Method of DoubleKey class.

Example

Saves public key to a file from randomly generated key pair; returns an integer indicating whether key saved successfully -1 or failed 0.

Syntax
SavePublicKey(strFile As String) As Long
StrFile Required. String expression that specifies a file name where public key to be saved; may include directory or folder, and drive.
 

  OpenKeyPair Function
Method of DoubleKey class.

Example

Reads a saved key pair from the file, StrKeyFile; returns an integer indicating whether key pair was opened successfully -1 or failed 0. Key pair is used when decoding file, since it contains private key.

Syntax
OpenKeyPair(StrKeyFile As String) As StringKey
StrKeyFile Required.  File name where the key value was saved.
 

  OpenPublicKey Function
Method of DoubleKey class.

Example

Reads from the file public key of the saved key pair ; returns an integer indicating whether pubic key  was opened successfully -1 or failed 0. Public key is used when encoding file.

Syntax
OpenPublicKey(StrKeyFile As String) As StringKey
StrKeyFile Required.  File name where the key value was saved.
 

  Calling MagicCrypt Object from VB for DoubleKey class

To call the MagicCrypt Object to use double key methods from Visual Basic, you will need to include the MagicCrypt.dll in the references and create the object using the following code:

Dim MyObject as MagicCryptLib.DoubleKey
Set MyObject=New MagicCryptLib.DoubleKey
To call the MagicCrypt Object to use single key methods from Active Server Pages, you may want to include the MagicCrypt.dll in the references and create the object using the following code:
Set MyObject = Server.CreateObject("MagicCrypt.DoubleKey")

 

  Generate Key Pair, Save KeyPair and Public Key using DoubleKey class

This example demonstrates how to use methods of a DoubleKey class, in particular how to generate a key pair and save it:
GenerateExchangeKeyPair, SaveKeyPair, SavePublicKey methods

Set MyObject = Server.CreateObject("MagicCrypt.DoubleKey")
MyObject.GenerateExchangeKeyPair
MyObject.SaveKeyPair "c:\Crypt\KeyPair.txt"
MyObject.SavePublicKey "c:\Crypt\PublicKey.txt"

 

  Open Public Key and Encode File using DoubleKey Class

This example demonstrates how to use methods of a DoubleKey class, in particular how to encode file using public key or key pair:
OpenPublicKey,OpenKeyPair, EncodeFile

Set MyObject = Server.CreateObject("MagicCrypt.DoubleKey")
MyObject.OpenPublicKey "c:\Crypt\PublicKey.txt"
MyObject.EncodeFile "c:\Crypt\EncodeFile1.txt", "c:\Crypt\MyFile.txt"
MyObject.Reset
 
MyObject.OpenKeyPair "c:\Crypt\KeyPair.txt"
MyObject.EncodeFile "c:\Crypt\EncodeFile2.txt", "c:\Crypt\MyFile.txt"
MyObject.Reset

 

  Open Key Pair and Decode File using DoubleKey Class

This example demonstrates how to use methods of a DoubleKey class, in particular how to decode file using private key by opening key pair:
OpenKeyPair, DecodeFile

Set MyObject = Server.CreateObject("MagicCrypt.DoubleKey")
 
MyObject.OpenKeyPair "c:\Crypt\KeyPair.txt"
MyObject.DecodeFile "c:\Crypt\DecodeFile1.txt", "c:\Crypt\EncodeFile1.txt"
MyObject.DecodeFile "c:\Crypt\DecodeFile2.txt", "c:\Crypt\EncodeFile2.txt"
MyObject.Reset

 

Lists of algorithms supported by different Cryptographic Providers

Algorithm ID Value Description Microsoft
Base Cryptographic
Provider
Microsoft
Enhanced
Cryptographic
Provider
Microsoft
DSS
Cryptographic
Provider
Microsoft
Base DSS
and Diffie-Hellman
Cryptographic
Provider
Microsoft
RSA/Schannel
Cryptographic
Provider
Microsoft
DSS and
Diffie-Hellman/
Schannel
Cryptographic
Provider
 CALG_SSL3_SHAMD5 32776 SLL3 client authentication algorithm. Y Y        
 CALG_RSA_SIGN 9216 RSA public-key signature algorithm. Y Y        
 CALG_RSA_KEYX 41984 RSA public-key exchange algorithm. Y Y     Y  
 CALG_RC2 26114 RC2 block encryption algorithm. Y Y     Y Y
 CALG_RC4 26625 RC4 stream encryption algorithm. Y Y     Y Y
 CALG_DES 26113 DES encryption   Y        
 CALG_3DES_112 26121 Two key triple DES encryption   Y        
 CALG_3DES 26115 Triple DES.   Y        
 CALG_DSS_SIGN 8704 DSS public/private-key signature algorithm.      Y Y    
 CALG_DH_SF 43521 Store and Forward D-H key exchange.       Y   Y
 CALG_DH_EPHEM 43522 Ephemeral D-H key exchange.       Y   Y
 CALG_CYLINK_MEK 26124 A 40-bit variant of a DES key.       Y   Y
 Hashing algorithms
 CALG_MD2 32769 MD2 hashing algorithm. Y Y        
 CALG_MD5 32771 MD5 hashing algorithm. Y Y Y Y Y Y
 CALG_SHA 32772 SHA hashing algorithm. Y Y Y Y Y Y
 CALG_SHA1 32772 Same as CALG_SHA. Y Y Y Y    
 CALG_MAC 32773 MAC keyed-hash algorithm. Y Y        
 CALG_HMAC 32777 MAC keyed-hash algorithm. Y Y        
top


Web Design - Web design company Digimode in London, with the best webdesign showcase, offers web design, SEO and Pay per click.
JIT Systems bespoke software - JIT Systems is a bespoke software development company based in Sussex specialising in business software and web applications. We develop bespoke software applications around a set of highly robust and flexible core components.

Home | FAQ | News | How to buy | Contacts | ASP MagicPerf Component | ASP MagicShell Component | Website Monitoring Blog
Our friends: FatCow Web Hosting