Hiding a value in message

Hi,

We know that message headers can be used to add secret values to the message that can be retrieved at the receiving end. However, this isn’t much safe as anyone can explore the headers section. Is there any other way to do it?

Thanks

Hi Alair,


Thank you for your inquiry.

You can also set the secret data in MapiMessage properties as well, but that is also the same as setting the value in header. These are accessible by anyone who reads the message for detecting such data. However, you can encrypt your data using some private key that is known to you and at the receiver’s end. This way if the data is detected by someone even, it will be in encrypted format and not readable by unintentional users. Other than this method, there is no technique available for hiding data in a message.

Hi Muhammad,

Can you please share a working code sample? Many thanks

Hi Alair,

Following is a sample code which can be used to set and get encrypted property from a MapiMessage. Please give it a try and let us know your feedback.

static void Main(string[] args)
{
    email_622928_SetProperty();
    email_622928_GetProperty();
    Console.WriteLine("Press any key to continue...");
    Console.ReadKey();
}

static void email_622928_SetProperty()
{
    int YOUR_XOR_KEY = 194;
    string YOUR_DATA_STRING = "This is a simple data text. Use your own data string here.";
    string encryptedData = EncryptDecryptData(YOUR_XOR_KEY, YOUR_DATA_STRING);

    //Print your encoded data
    Debug.WriteLine("Encrypted Data: " + encryptedData);

    using (MapiMessage msg = new MapiMessage("user1@gmail.com", "user2@gmail.com", "Sample Subject", "Sample Body"))
    {
        MapiProperty property = new MapiProperty(msg.NamedPropertyMapping.GetNextAvailablePropertyId(MapiPropertyType.PT_UNICODE), Encoding.Unicode.GetBytes(encryptedData));
        msg.AddCustomProperty(property, "StringProp");
        msg.Save(@"Output.msg");
    }
}

static void email_622928_GetProperty()
{
    MapiMessage mapi = MapiMessage.FromFile(@"Output.msg");

    foreach (MapiProperty mapiProp in mapi.NamedProperties.Values)
    {
        MapiNamedProperty namedProperty = (MapiNamedProperty)mapiProp;

        if (namedProperty.NameId == "StringProp")
        {
            String EncryptedData = namedProperty.GetString();
            int YOUR_XOR_KEY = 194;
            string decryptedData = EncryptDecryptData(YOUR_XOR_KEY, EncryptedData);

            //Print your decoded data
            Console.WriteLine("Decrypted Data: " + decryptedData);
        }
    }
}

static string EncryptDecryptData(int key, string input)
{
    //Read original file as byte array
    char[] originalBytes = input.ToCharArray();

    //Create output string
    string outputString = string.Empty;

    //Loop through all bytes in original array and encode each byte using XOR operation
    for (int i = 0; i < originalBytes.Length; i++)
    {
        outputString += (char)(originalBytes[i] ^ key);
    }

    return outputString;
}