// Sebastien Pouliot (sebastien@ximian.com)
//
// (C) 2002, 2003 Motus Technologies Inc. (http://www.motus.com)
-// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2004-2007 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// b. IETF RFC2898: PKCS #5: Password-Based Cryptography Specification Version 2.0
// http://www.rfc-editor.org/rfc/rfc2898.txt
-#if NET_2_0
[ComVisible (true)]
-#endif
public class PasswordDeriveBytes : DeriveBytes {
private string HashNameValue;
}
}
-#if NET_2_0
public PasswordDeriveBytes (byte[] password, byte[] salt)
{
Prepare (password, salt, "SHA1", 100);
Locale.GetText ("CspParameters not supported by Mono for PasswordDeriveBytes."));
}
}
-#endif
- ~PasswordDeriveBytes ()
+ protected override void Dispose (bool disposing)
{
// zeroize buffer
if (initial != null) {
initial = null;
}
// zeroize temporary password storage
- Array.Clear (password, 0, password.Length);
+ if (password != null) {
+ Array.Clear (password, 0, password.Length);
+ password = null;
+ }
+ base.Dispose (disposing);
}
-#if NET_2_0
private void Prepare (string strPassword, byte[] rgbSalt, string strHashName, int iterations)
{
if (strPassword == null)
IterationCount = iterations;
state = 0;
}
-#else
- private void Prepare (string strPassword, byte[] rgbSalt, string strHashName, int iterations)
- {
- if (strPassword == null)
- password = null;
- else
- password = Encoding.UTF8.GetBytes (strPassword);
-
- if (rgbSalt == null)
- SaltValue = null;
- else
- SaltValue = (byte[]) rgbSalt.Clone ();
-
- HashName = strHashName;
- IterationCount = iterations;
- state = 0;
- }
-#endif
-
public string HashName {
get { return HashNameValue; }
set {
throw new CryptographicException (
Locale.GetText ("Can't change this property at this stage"));
}
-#if NET_2_0
if (value != null)
SaltValue = (byte[]) value.Clone ();
else
SaltValue = null;
-#else
- // this will cause a NullReferenceException if set to null (like 1.0/1.1)
- SaltValue = (byte[]) value.Clone ();
-#endif
}
}
}
// note: Key is returned - we can't zeroize it ourselve :-(
-#if NET_2_0
[Obsolete ("see Rfc2898DeriveBytes for PKCS#5 v2 support")]
-#endif
+ #pragma warning disable 809
public override byte[] GetBytes (int cb)
{
-#if ! NET_2_0
- // 1.0/1.1 was a little late at throwing the argument exception ;-)
- if (password == null)
- throw new ArgumentNullException ("Password");
-#endif
+ #pragma warning restore 809
+
if (cb < 1)
throw new IndexOutOfRangeException ("cb");
if (state == 0) {
- state = 1;
// it's now impossible to change the HashName, Salt
// and IterationCount
Reset ();
+ state = 1;
}
byte[] result = new byte [cb];
public override void Reset ()
{
- // note: Reset doesn't change state
+ state = 0;
position = 0;
hashnumber = 0;