 |
 |
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. 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:
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
- 1-CPU Licence $199
- 2-CPU Licence $299
- 3-CPU Licence $399
- (only within one organization)
Also, you may order by sending check to: .
(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.
|
|
|
 |
| |
Working with MagicCrypt
SingleKey
DoubleKey
-
SingleKey Class Methods
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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 ().
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 ().
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
|
|
|
| |
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 – name of the provider.
|
Example of available Microsoft provider’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
|
|
|
| |
| |
-
DoubleKey Class Methods
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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
|