RC2CryptoServiceProvider |
IObject | |
RC2 | |
SymmetricAlgorithm |
Name | Description |
---|---|
![]() | Returns the block size, in bits, used by this algorithm. |
![]() | Sets the block size, in bits, used by this algorithm. |
![]() | Returns the effective key size to be used. |
![]() | Sets the effective key size to be used. |
![]() | Returns the Feedback Size in bits. |
![]() | Sets the Feedback size in bits. |
![]() | Returns the Initialization Vector. |
![]() | Sets the Initialization Vector to be used. |
![]() | Returns the current secret key. |
![]() | Sets the secret key. |
![]() | Returns the key size in bits. |
![]() | Sets the key size in bits. |
![]() | Returns a list of legal block sizes. |
![]() | Returns a list of valid key sizes supported by this algorithm. |
![]() | Returns the Cipher mode this algorithm will use. |
![]() | Sets the Cipher mode this algorithm will use. |
![]() | Returns the padding mode being used. |
![]() | Sets the padding mode to be used. |
![]() | Returns if a salt value is to be used with the key generation. |
![]() | Sets if a salt value will be used with the key generation. |
Name | Description |
---|---|
![]() | Clears the Key and IV arrays. |
![]() | Returns a new cipher used to decrypt data. |
![]() | Returns a new cipher used to encrypt data. |
![]() | This function determines if the value passed in is the same as the current object instance. Meaning, are the Value and this object the same object in memory. |
![]() | Generates a random IV array to use. |
![]() | Generates a random key to be used. |
![]() | Returns a psuedo-unique number used to help identify this object in memory. The current method is to return the value obtained from ObjPtr. If a different method needs to be impelmented then change the method here in this function. |
![]() | Returns a string representation of this object instance. The default method simply returns the application name and class name in which this class resides. |
![]() | Tests if a specific bit length is valid for a key. |
This class uses the Windows CryptoAPI services.
This example shows a very simple method of encrypting then decrypting a String value.
Private Sub Main() Dim Buffer() As Byte Dim PlainText As String ' Create a new RC2CryptoServiceProvider key. Dim Key As New RC2CryptoServiceProvider ' Encrypt a string to a byte array. Buffer = Encrypt("This is some plaintext!", Key) Debug.Print "Encrypted data" PrintBytes Buffer Debug.Print ' Decrypt the byte array back to a string. PlainText = Decrypt(Buffer, Key) ' Display the plaintext value to the console. Debug.Print "Decrypted data" Debug.Print PlainText End Sub Private Sub PrintBytes(ByRef Bytes() As Byte) Dim i As Long For i = LBound(Bytes) To UBound(Bytes) Debug.Print Object.ToString(Bytes(i), "X2"); " "; Next Debug.Print End Sub ' Encrypt the string. Private Function Encrypt(ByVal PlainText As String, ByVal Key As SymmetricAlgorithm) As Byte() Dim Encryptor As ICryptoTransform Dim Buffer() As Byte Buffer = Encoding.UTF8.GetBytes(PlainText) Set Encryptor = Key.CreateEncryptor Encrypt = Encryptor.TransformFinalBlock(Buffer, 0, CorArray.Length(Buffer)) End Function ' Decrypt the byte array. Public Function Decrypt(ByRef CypherText() As Byte, ByVal Key As SymmetricAlgorithm) As String Dim Decryptor As ICryptoTransform Dim Buffer() As Byte Set Decryptor = Key.CreateDecryptor Buffer = Decryptor.TransformFinalBlock(CypherText, 0, CorArray.Length(CypherText)) Decrypt = Encoding.UTF8.GetString(Buffer) End Function ' This example code produces the following output. (encrypted data may be different because key is random) ' ' Encrypted Data ' B3 70 EC 9E 4C 6F A1 43 CA 1E 64 68 95 E5 0C A0 E0 71 0B DA CB 09 B4 42 ' ' Decrypted Data ' This is some plaintext!