There are certain requirements when you need to send encrypted messages to make sure the data you're sending is secure. You can use encryption in two ways. First, you can encrypt a message itself. Second, you can use queuing services to encrypt a message through the MessageQueue class.
To encrypt a message, you can use the DestinationSymmetricKey property of a message and then send this message to the queue. The DestinationSymmetricKey property represents the symmetric key used to encrypt application-encrypted messages.
The EncryptionRequired property of MessageQueue sets whether a queue accepts nonencrypted or encrypted messages. The EncryptionRequired enumeration provides the value of the EncryptionRequired property, which has three values: Body, None, and Optional. The Body option makes sure the queue only accepts private (encrypted) messages. The None option means the queue accepts only nonencrypted messages. The Optional option means the queue accepts both encrypted and nonencrypted messages.
The EncryptionAlgorithm property of the Message class represents the type of encryption applied on a message. This property is represented by the EncryptionAlgorithm enumeration, which has three values: None, RC2, and RC4. The value None means no encryption. RC2 is a 64-bit block encryption, and RC4 is the stream encryption. The block mode encrypts a block of data at a time, and the stream mode encrypts a bit at a time.
Listing 21-10 sends encrypted messages. As you can see, it sets the UseEncryption property of a Message object to activate the encryption.
Listing 21-10: Sending Encrypted Messages
Try Dim msg As System.Messaging.Message = _ New System.Messaging.Message(titleTextBox.Text) MessageQueue1.EncryptionRequired = _ Messaging.EncryptionRequired.Body msg.UseEncryption = True If (rc4RadioBtn.Checked) Then msg.EncryptionAlgorithm = Messaging.EncryptionAlgorithm.Rc4 ElseIf (rc2RadioBtn.Checked) Then msg.EncryptionAlgorithm = Messaging.EncryptionAlgorithm.Rc2 Else msg.EncryptionAlgorithm = Messaging.EncryptionAlgorithm.None End If msg.Label = titleTextBox.Text msg.Body = bodyTextBox.Text MessageQueue1.Send(msg) Catch exp As Exception MessageBox.Show(exp.Message) End Try