我使用其中提供HereTripleDESCryptoServiceProvider在WP7
我得到在桌面代碼相同加密字符串TripleDESCryptoServiceProvider類加密字符串(未WP7簡單的C#)與動初始化向量= {0,0,0,0, 0,0,0,0} 但如果我改變IV爲{64,64,64,64,64,64,64,64}我得到不同的加密字符串。 從字節字符串轉換我使用base64編碼。 這裏是我的代碼: 注意:如果我使用WP7加密字符串在桌面解密前8個字符不能正確解密,其餘字符是正確的。意味着在「你好我的朋友!我用TripleDES安全:)」);只有「結束!我用TripleDES :)安全」這很正確。一些垃圾在開始。
private static byte[] sharedkey ={
0x01, 0x02, 0x03, 0x05, 0x07, 0x0B, 0x0D, 0x11,
0x12, 0x11, 0x0D, 0x0B, 0x07, 0x02, 0x04, 0x08,
0x01, 0x02, 0x03, 0x05, 0x07, 0x0B, 0x0D, 0x11
};
private static byte[] sharedvector = new byte[] { 64, 64, 64, 64, 64, 64, 64, 64 };
VAR toEncrypt = Encoding.UTF8.GetBytes( 「嗨!我的朋友,我用了TripleDes安全:)」);
TripleDESCryptoServiceProvider tdesAlgorithm = new TripleDESCryptoServiceProvider();
// Create the encryptor
ICryptoTransform encryptor = tdesAlgorithm.CreateEncryptor(sharedkey, sharedvector);
var cryptedBytes = encryptor.TransformFinalBlock(toEncrypt, 0, toEncrypt.Length);
// Create the decryptor
ICryptoTransform decryptor = tdesAlgorithm.CreateDecryptor(sharedkey, sharedvector);
var decryptedBytes = decryptor.TransformFinalBlock(cryptedBytes, 0, cryptedBytes.Length);
var uncryptedString = Encoding.UTF8.GetString(decryptedBytes, 0, decryptedBytes.Length);
編輯:看起來像歐洲央行,四被忽略。在由Nocolus提供的代碼中。請你告訴我如何改變這種情況。
其posiible是否使用DES/CBC模式在WP7 – Mahantesh 2012-02-09 12:20:47
在你提到的帖子中提供的鏈接,它說 '對於加密每個塊,塊首先與先前block.'異或 那是CBC。 – abhinav 2012-02-09 13:18:22
我的主管用你的幫助做了非常感謝。 – Mahantesh 2012-02-15 10:46:44