質問
TripleDES 暗号化用のバイト配列を生成する必要があります。使いたくない .generateKey()
別のアプリケーションにキーを渡すためにキー内のバイトを知る必要があるからです。
ご返信ありがとうございます。ただし、1 つ言及するのを忘れていました。バイトは奇数パリティである必要があります。そうしないと、それらから TripleDES キーを生成できません。私は奇数パリティについてはあまり詳しくないので、奇数パリティがあるかどうかのバイトチェックを作成する必要があると思います。配列に配置する場合は配列に配置し、そうでない場合は配置しません。
解決
奇数パリティを確保する必要がある場合は、自分で計算する必要があります。これは次のことを行う必要があります: ジェネラコディセタグプレ
他のヒント
どうでしょうか:
RandomNumberGenerator rng = RandomNumberGenerator.Create();
byte[] key = new byte[24]; // For a 192-bit key
rng.GetBytes(key);
tripleDes.Key = key;
ご了承ください RandomNumberGenerator
(適度に安全で予測が難しいランダム データという点で) 暗号化作業に適していますが、 System.Random
そうではありません。
But ... what's the problem with just:
TripleDES provider = TripleDES.Create();
byte[] key = provider.Key;
There you get your key used by the en- and decryptor created with this instance.
Note that the other answers lack a TripleDES.IsWeakKey
.
The GetBytes method returns crypthographically strong sequence of values:
var rng = System.Security.Cryptography.RandomNumberGenerator.Create();
byte [] barr = new byte[128];
rng.GetBytes(barr);
foreach (var b in barr)
{
Console.WriteLine(b);
}
What about Random.NextBytes()
More info here.