Browse Source

2005-10-27 Sebastien Pouliot <[email protected]>

	* ProtectedData.cs: Added support for Windows (2000 and later) by 
	p/invoking DPAPI thru Mono.Security.Cryptography.NativeDapiProtection.


svn path=/trunk/mcs/; revision=52282
Sebastien Pouliot 20 years ago
parent
commit
f712b8fd3f

+ 5 - 0
mcs/class/System.Security/System.Security.Cryptography/ChangeLog

@@ -1,3 +1,8 @@
+2005-10-27  Sebastien Pouliot  <[email protected]>
+
+	* ProtectedData.cs: Added support for Windows (2000 and later) by 
+	p/invoking DPAPI thru Mono.Security.Cryptography.NativeDapiProtection.
+
 2005-10-20  Sebastien Pouliot  <[email protected]>
 
 	* CryptographicAttributeCollection.cs: Fixed Add and Remove methods.

+ 14 - 2
mcs/class/System.Security/System.Security.Cryptography/ProtectedData.cs

@@ -46,7 +46,6 @@ namespace System.Security.Cryptography {
 		{
 		}
 
-		[MonoTODO ("not (yet) supported on Windows")]
 // FIXME	[DataProtectionPermission (SecurityAction.Demand, ProtectData = true)]
 		public static byte[] Protect (byte[] userData, byte[] optionalEntropy, DataProtectionScope scope) 
 		{
@@ -66,12 +65,18 @@ namespace System.Security.Cryptography {
 					throw new CryptographicException (msg, e);
 				}
 			case DataProtectionImplementation.Win32CryptoProtect:
+				try {
+					return NativeDapiProtection.Protect (userData, optionalEntropy, scope);
+				}
+				catch (Exception e) {
+					string msg = Locale.GetText ("Data protection failed.");
+					throw new CryptographicException (msg, e);
+				}
 			default:
 				throw new PlatformNotSupportedException ();
 			}
 		}
 
-		[MonoTODO ("not (yet) supported on Windows")]
 // FIXME	[DataProtectionPermission (SecurityAction.Demand, UnprotectData = true)]
 		public static byte[] Unprotect (byte[] encryptedData, byte[] optionalEntropy, DataProtectionScope scope) 
 		{
@@ -91,6 +96,13 @@ namespace System.Security.Cryptography {
 					throw new CryptographicException (msg, e);
 				}
 			case DataProtectionImplementation.Win32CryptoProtect:
+				try {
+					return NativeDapiProtection.Unprotect (encryptedData, optionalEntropy, scope);
+				}
+				catch (Exception e) {
+					string msg = Locale.GetText ("Data unprotection failed.");
+					throw new CryptographicException (msg, e);
+				}
 			default:
 				throw new PlatformNotSupportedException ();
 			}