Outlook电子邮件地址:字符编码或编码电子邮件地址支持 [英] Outlook Email Address: Character encoding or encode Email address support

查看:170
本文介绍了Outlook电子邮件地址:字符编码或编码电子邮件地址支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


我正在尝试加密&编码我通过Outlook"To"获取的电子邮件地址。领域。我面临的问题是,如果采用unicode格式,我无法对这些字符串进行加密和编码。代码片段
最后粘贴以供参考。



我用来检查有效电子邮件地址的对象是:  System.Net.Mail。 MailAddress


问题:


1。什么是Outlook 2013和Outlook 2016(Exchange Server 2010)中对非英文字符的支持?


2。是什么支持Outlook 2013和Outlook 2016中的非英文字符(Exchange server Online)?


3。如何实现加密&为输入"To"编码这些字符。地址字段?



示例电子邮件地址:


Pelé@example.com


  δοκιμή@ παράδειγμα.δοκιμή


  ; 我买 @ 屋企香港


甲斐 @ 黒川日本


чебурашка@ящик-с-апельсинами.рф


संपर्क @ डाटामेलभारत $


代码:

 string plaintext ="чебурашка@ящик-с-апельсинами.рф"
string passphrase ="xyz @ 123";


private const int Keysize = 256;

//此常量确定密码字节生成函数的迭代次数。
private const int DerivationIterations = 1000;

公共静态字符串Encrypt(string plainText,string passPhrase)
{
//每次随机生成Salt和IV,但是预先加密到加密的密文
//以便相同解密时可以使用Salt和IV值。
var saltStringBytes = Generate256BitsOfRandomEntropy();
var ivStringBytes = Generate256BitsOfRandomEntropy();
var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
using(var password = new Rfc2898DeriveBytes(passPhrase,saltStringBytes,DerivationIterations))
{
var keyBytes = password.GetBytes(Keysize / 8);
using(var symmetricKey = new RijndaelManaged())
{
symmetricKey.BlockSize = 256;
symmetricKey.Mode = CipherMode.CBC;
symmetricKey.Padding = PaddingMode.PKCS7;
using(var encryptor = symmetricKey.CreateEncryptor(keyBytes,ivStringBytes))
{
using(var memoryStream = new MemoryStream())
{
using(var cryptoStream) = new CryptoStream(memoryStream,encryptor,CryptoStreamMode.Write))
{
cryptoStream.Write(plainTextBytes,0,plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
//创建最后的字节,作为随机盐字节,随机iv字节和密码字节的串联。
var cipherTextBytes = saltStringBytes;
cipherTextBytes = cipherTextBytes.Concat(ivStringBytes).ToArray();
cipherTextBytes = cipherTextBytes.Concat(memoryStream.ToArray())。ToArray();
memoryStream.Close();
cryptoStream.Close();
返回Convert.ToBase64String(cipherTextBytes);
}
}
}
}
}
}

公共静态字符串Decrypt(string cipherText,string passPhrase)
{
//获取完整的字节流,代表:
// [32字节的盐] + [32字节的IV] + [n字节的CipherText]
var cipherTextBytesWithSaltAndIv = Convert.FromBase64String(cipherText);
//通过从提供的cipherText字节中提取前32个字节来获取saltbytes。
var saltStringBytes = cipherTextBytesWithSaltAndIv.Take(Keysize / 8).ToArray();
//通过从提供的cipherText字节中提取下一个32字节来获取IV字节。
var ivStringBytes = cipherTextBytesWithSaltAndIv.Skip(Keysize / 8).Take(Keysize / 8).ToArray();
//通过从cipherText字符串中删除前64个字节来获取实际的密文字节。
var cipherTextBytes = cipherTextBytesWithSaltAndIv.Skip((Keysize / 8)* 2).Take(cipherTextBytesWithSaltAndIv.Length - ((Keysize / 8)* 2))。ToArray();

使用(var password = new Rfc2898DeriveBytes(passPhrase,saltStringBytes,DerivationIterations))
{
var keyBytes = password.GetBytes(Keysize / 8);
using(var symmetricKey = new RijndaelManaged())
{
symmetricKey.BlockSize = 256;
symmetricKey.Mode = CipherMode.CBC;
symmetricKey.Padding = PaddingMode.PKCS7;
using(var decryptor = symmetricKey.CreateDecryptor(keyBytes,ivStringBytes))
{
using(var memoryStream = new MemoryStream(cipherTextBytes))
{
using(var cryptoStream = new CryptoStream(memoryStream,decryptor,CryptoStreamMode.Read))
{
var plainTextBytes = new byte [cipherTextBytes.Length];
var decryptedByteCount = cryptoStream.Read(plainTextBytes,0,plainTextBytes.Length);
memoryStream.Close();
cryptoStream.Close();
返回Encoding.UTF8.GetString(plainTextBytes,0,decryptedByteCount);
}
}
}
}
}
}

private static byte [] Generate256BitsOfRandomEntropy()
{
var randomBytes = new byte [32]; // 32字节将给我们256位。
using(var rngCsp = new RNGCryptoServiceProvider())
{
//用加密安全随机字节填充数组。
rngCsp.GetBytes(randomBytes);
}
返回randomBytes;
}





解决方案

您好MSDN_Geek,



感谢您的帖子。



对于您的问题1和2,您提供的Unicode地址不会由基于服务器的RFC 5322处理,
但RFC 6530允许使用Unicode地址.RFC 6530提供基于UTF-8编码的电子邮件地址,该编码允许完整的Unicode库。因此基于RFC6530的服务器将能够处理这些服务器。
 


至于你的问题3,我测试过了你的代码,它正常工作。因此,您可以再次尝试使用代码。



如果您有任何其他问题,请随时与我联系。


最诚挚的问候,


Wendy


Hello,

I am trying to encrypt & encode the email address which i am fetching through the Outlook "To" field. The issue i am facing is i am unable to encrypt and encode these string if in unicode formats. The code snippet is pasted in the end for reference.

The object i am using to check the valid email address is : System.Net.Mail.MailAddress

Question:

1. Whats the support for non-english characters in Outlook 2013 and Outlook 2016 (Exchange server 2010)?

2. Whats the support for non-english characters in Outlook 2013 and Outlook 2016 (Exchange server Online)?

3. How to achieve the encrypt & encoding of these characters for the input "To" address field ?

Example Email address:

Pelé@example.com

 δοκιμή@παράδειγμα.δοκιμή

 我買@屋企.香港

甲斐@黒川.日本

чебурашка@ящик-с-апельсинами.рф

संपर्क@डाटामेल.भारत

Code:

string plaintext = "чебурашка@ящик-с-апельсинами.рф"
string passphrase = "xyz@123";


private const int Keysize = 256;

        // This constant determines the number of iterations for the password bytes generation function.
        private const int DerivationIterations = 1000;

        public static string Encrypt(string plainText, string passPhrase)
        {
            // Salt and IV is randomly generated each time, but is preprended to encrypted cipher text
            // so that the same Salt and IV values can be used when decrypting.  
            var saltStringBytes = Generate256BitsOfRandomEntropy();
            var ivStringBytes = Generate256BitsOfRandomEntropy();
            var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
            using (var password = new Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations))
            {
                var keyBytes = password.GetBytes(Keysize / 8);
                using (var symmetricKey = new RijndaelManaged())
                {
                    symmetricKey.BlockSize = 256;
                    symmetricKey.Mode = CipherMode.CBC;
                    symmetricKey.Padding = PaddingMode.PKCS7;
                    using (var encryptor = symmetricKey.CreateEncryptor(keyBytes, ivStringBytes))
                    {
                        using (var memoryStream = new MemoryStream())
                        {
                            using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
                            {
                                cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
                                cryptoStream.FlushFinalBlock();
                                // Create the final bytes as a concatenation of the random salt bytes, the random iv bytes and the cipher bytes.
                                var cipherTextBytes = saltStringBytes;
                                cipherTextBytes = cipherTextBytes.Concat(ivStringBytes).ToArray();
                                cipherTextBytes = cipherTextBytes.Concat(memoryStream.ToArray()).ToArray();
                                memoryStream.Close();
                                cryptoStream.Close();
                                return Convert.ToBase64String(cipherTextBytes);
                            }
                        }
                    }
                }
            }
        }

        public static string Decrypt(string cipherText, string passPhrase)
        {
            // Get the complete stream of bytes that represent:
            // [32 bytes of Salt] + [32 bytes of IV] + [n bytes of CipherText]
            var cipherTextBytesWithSaltAndIv = Convert.FromBase64String(cipherText);
            // Get the saltbytes by extracting the first 32 bytes from the supplied cipherText bytes.
            var saltStringBytes = cipherTextBytesWithSaltAndIv.Take(Keysize / 8).ToArray();
            // Get the IV bytes by extracting the next 32 bytes from the supplied cipherText bytes.
            var ivStringBytes = cipherTextBytesWithSaltAndIv.Skip(Keysize / 8).Take(Keysize / 8).ToArray();
            // Get the actual cipher text bytes by removing the first 64 bytes from the cipherText string.
            var cipherTextBytes = cipherTextBytesWithSaltAndIv.Skip((Keysize / 8) * 2).Take(cipherTextBytesWithSaltAndIv.Length - ((Keysize / 8) * 2)).ToArray();

            using (var password = new Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations))
            {
                var keyBytes = password.GetBytes(Keysize / 8);
                using (var symmetricKey = new RijndaelManaged())
                {
                    symmetricKey.BlockSize = 256;
                    symmetricKey.Mode = CipherMode.CBC;
                    symmetricKey.Padding = PaddingMode.PKCS7;
                    using (var decryptor = symmetricKey.CreateDecryptor(keyBytes, ivStringBytes))
                    {
                        using (var memoryStream = new MemoryStream(cipherTextBytes))
                        {
                            using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
                            {
                                var plainTextBytes = new byte[cipherTextBytes.Length];
                                var decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
                                memoryStream.Close();
                                cryptoStream.Close();
                                return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
                           }
                        }
                    }
                }
            }
        }

        private static byte[] Generate256BitsOfRandomEntropy()
        {
            var randomBytes = new byte[32]; // 32 Bytes will give us 256 bits.
            using (var rngCsp = new RNGCryptoServiceProvider())
            {
                // Fill the array with cryptographically secure random bytes.
                rngCsp.GetBytes(randomBytes);
            }
            return randomBytes;
        }


解决方案

Hi MSDN_Geek,

Thanks for your post.

For your questions 1 and 2, the Unicode addresses you give would not be handled by RFC 5322 based on servers, but Unicode address are permitted by RFC 6530. RFC 6530 provides email address based on the UTF-8 encoding, which permits the full repertoire of Unicode. So servers which based on RFC6530 will be able to handle these. 

As for your question 3, I have tested your codes and it works properly. So, you could try your code once again.

If you have any other questions, please feel free to contact me.

Best Regards,

Wendy


这篇关于Outlook电子邮件地址:字符编码或编码电子邮件地址支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆