Products » dgEncrypt User Guide

Method:  Cipher::SetKey

SetKey(Key)

As its name implies, the SetKey method uses the key value contained within a Key object to set the key that will be used in encrypting and decrypting strings and files. The SetKey method must be called at least once before any of the Cipher object's encryption and decryption methods are used, or an error will result. The SetKey method may, however, be called multiple times, with each call setting the key to a new value.

 
Key
The key argument is a previously initialized Key object. Note that the Rijndael cipher is only defined for key lengths of 16 bytes, 24 bytes, or 32 bytes, and that Key objects whose key values have lengths other than these will produce an error when passed to the SetKey method.
 
Example:
<%
Dim objKey
Dim objCipher

Set objKey = Server.CreateObject("dgEncrypt.Key")
objKey.GenerateKey 17

Set objCipher = Server.CreateObject("dgEncrypt.Cipher")
objCipher.SetKey objKey

Set objCipher = Nothing
Set objKey = Nothing
%>

 
Output:
    . . .

  • Error Type:
    dgEncrypt.Cipher (0x80070057)
    SetKey: invalid key length keys must be 16, 24, or 32 bytes in length
    /somewhere/dgEncrypt_test.asp, line 9