Rijndael算法(如何创建自己的密钥) [英] Rijndael algorithm (How to create our own Key )

查看:512
本文介绍了Rijndael算法(如何创建自己的密钥)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有Rijndael算法的样本被定义从Rijndael算法类本身的关键,我们不能提供我们自己的关键。在这个任何暗示将帮助我很多东西。



我们正在创建示例应用程序是为Windows Mobile,它不支持PasswordDeriveBytes


提前
Geetha关于这一主题



更新

感谢:
按下面提供的代码示例中,我们已经尝试它,它似乎是工作,但有一个小嗝于此。当我们解密数据有一个8位的填充了上例中的值的右侧,我们加密了交易的唯一密钥,它看起来是这样的:



加密前:
MI03112009044625000000000000008024754008



解密后:
MI03112009044625000000000000008024754008揞⑁㋬㓠⥳空⠜资



任何人都可以在这个右填充的原始值发生有所帮助。



由于
Geetha

解决方案

您可以尝试这样的事情的基础上的 RijndaelManaged类MSDN文章,我也建议你阅读。

  VAR明文=这将被加密。 
变种aesAlg =新RijndaelManaged的();
aesAlg.Key =新的字节[32] {118,123,23,17,161,152,35,68,126,213,16,115,68,217,58,108,56,218, 5,78,28,128,113,208,61,56,10,87,187,162,233,38};
aesAlg.IV =新的字节[16] {33,241,14,16,103,18,14,248,4,54,18,5,60,76,16,191};
ICryptoTransform的加密= aesAlg.CreateEncryptor(aesAlg.Key,aesAlg.IV);

msEncrypt =新的MemoryStream();
使用(CryptoStream的csEncrypt =新的CryptoStream(msEncrypt,加密,CryptoStreamMode.Write)){使用
(StreamWriter的swEncrypt =新的StreamWriter(csEncrypt)){
swEncrypt.Write(明文);
}
}

返回msEncrypt.ToArray();


All the samples for Rijndael algorithm are defining the key from the Rijndael class itself, can't we provide the Key of our own. Any hint on this will help me a lot.

The sample application we are creating is for windows mobile and it doesn't support PasswordDeriveBytes

Thanks in advance Geetha

Update on this topic: As per the code sample provided below, we have tried it and it seems to be working but there is a small hiccup in this. when we decrypt the data there is a 8 bit padding up on the right side of the value for the example, we are encrypting a Unique key for transaction and it looks like this :

Before encryption: MI03112009044625000000000000008024754008

After Decryption: MI03112009044625000000000000008024754008揞⑁㋬㓠⥳空⠜資

can anyone help on this right padding happening in the original value.

thanks Geetha

解决方案

You can try something like this, based on the RijndaelManaged Class MSDN article that I also recommend you to read.

var plainText = "This will be encrypted.";
var aesAlg = new RijndaelManaged();
aesAlg.Key = new byte[32] { 118, 123, 23, 17, 161, 152, 35, 68, 126, 213, 16, 115, 68, 217, 58, 108, 56, 218, 5, 78, 28, 128, 113, 208, 61, 56, 10, 87, 187, 162, 233, 38 };
aesAlg.IV = new byte[16] { 33, 241, 14, 16, 103, 18, 14, 248, 4, 54, 18, 5, 60, 76, 16, 191};
ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV);

msEncrypt = new MemoryStream();
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) {
    using (StreamWriter swEncrypt = new StreamWriter(csEncrypt)) {
        swEncrypt.Write(plainText);
    }
}

return msEncrypt.ToArray();

这篇关于Rijndael算法(如何创建自己的密钥)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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