परावर्तक में कार्यान्वयन को देखकर से:
public Rfc2898DeriveBytes(string password, byte[] salt) : this(password, salt, 0x3e8)
{
}
public Rfc2898DeriveBytes(string password, int saltSize, int iterations)
{
if (saltSize < 0)
{
throw new ArgumentOutOfRangeException("saltSize", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
byte[] data = new byte[saltSize];
Utils.StaticRandomNumberGenerator.GetBytes(data);
this.Salt = data;
this.IterationCount = iterations;
this.m_hmacsha1 = new HMACSHA1(new UTF8Encoding(false).GetBytes(password));
this.Initialize();
}
public override byte[] GetBytes(int cb)
{
if (cb <= 0)
{
throw new ArgumentOutOfRangeException("cb", Environment.GetResourceString("ArgumentOutOfRange_NeedNonNegNum"));
}
byte[] dst = new byte[cb];
int dstOffset = 0;
int count = this.m_endIndex - this.m_startIndex;
if (count > 0)
{
if (cb < count)
{
Buffer.InternalBlockCopy(this.m_buffer, this.m_startIndex, dst, 0, cb);
this.m_startIndex += cb;
return dst;
}
Buffer.InternalBlockCopy(this.m_buffer, this.m_startIndex, dst, 0, count);
this.m_startIndex = this.m_endIndex = 0;
dstOffset += count;
}
while (dstOffset < cb)
{
byte[] src = this.Func();
int num3 = cb - dstOffset;
if (num3 > 20)
{
Buffer.InternalBlockCopy(src, 0, dst, dstOffset, 20);
dstOffset += 20;
}
else
{
Buffer.InternalBlockCopy(src, 0, dst, dstOffset, num3);
dstOffset += num3;
Buffer.InternalBlockCopy(src, num3, this.m_buffer, this.m_startIndex, 20 - num3);
this.m_endIndex += 20 - num3;
return dst;
}
}
return dst;
}
स्रोत
2009-12-20 22:27:28
यह प्रत्येक मंगलाचरण पर एक अलग कुंजी देता है लेकिन मुझे पता चला कुंजी लौटे हैं सभी एक ही – Kelvin
@Kelvin: आप यकीन है कि आप कर रहे हैं कर रहे हैं 'Rfc2898DeriveBytes' के उसी उदाहरण पर इसका उपयोग कर रहे हैं? 'Rfc2898DeriveBytes' के समान उदाहरण पर' Rfc2898DeriveBytes.GetBytes' के लगातार आमंत्रणों पर लौटाए गए वही बाइट्स को प्रभावी रूप से असंभव है। – jason
रिजेंडेल मैनेज्ड रिजेंडेलएएलजी = नया रिजेंडेल प्रबंधित(); स्ट्रिंग पासवर्ड = "11111111"; आरएफसी 28 9 8 डीरिवबाइट्स कुंजी = नया आरएफसी 28 9 8 डेरिवबाइट्स (पासवर्ड, एन्कोडिंग.एएससीआईआई.गेटबाइट्स ("22222222")); RijndaelAlg.Key = key.GetBytes (RijndaelAlg.KeySize/8); बाइट [] ए = कुंजी। गेटबाइट्स (32); (int i = 0; i
Kelvin