Ejemplo n.º 1
0
// FIXME	[DataProtectionPermission (SecurityAction.Demand, ProtectData = true)]
        public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtectionScope scope)
        {
            if (userData == null)
            {
                throw new ArgumentNullException("userData");
            }

            // on Windows this is supported only under 2000 and later OS
            Check(scope);

            switch (impl)
            {
            case DataProtectionImplementation.ManagedProtection:
                try {
                    return(ManagedProtection.Protect(userData, optionalEntropy, scope));
                }
                catch (Exception e) {
                    string msg = Locale.GetText("Data protection failed.");
                    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();
            }
        }
Ejemplo n.º 2
0
// FIXME	[DataProtectionPermission (SecurityAction.Demand, ProtectData = true)]
        public static byte[] Protect(byte[] userData, byte[] optionalEntropy, DataProtectionScope scope)
        {
            if (userData == null)
            {
                throw new ArgumentNullException("userData");
            }

            // on Windows this is supported by CoreFX implementation
            Check(scope);

            switch (impl)
            {
#if !MOBILE
            case DataProtectionImplementation.ManagedProtection:
                try {
                    return(ManagedProtection.Protect(userData, optionalEntropy, scope));
                }
                catch (Exception e) {
                    string msg = Locale.GetText("Data protection failed.");
                    throw new CryptographicException(msg, e);
                }
#endif
            default:
                throw new PlatformNotSupportedException();
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Protected data using local user account
 /// </summary>
 /// <param name="data">Data to protect</param>
 /// <returns>Protected data</returns>
 public static byte[] Protect(byte[] data, byte[] optionalEntropy = null, DataProtectionScope scope = DataProtectionScope.CurrentUser)
 {
     if (CryptoUtility.IsWindows)
     {
         return(CryptOperationWindows(true, data, optionalEntropy, scope));
     }
     else
     {
         return(ManagedProtection.Protect(data, optionalEntropy, scope));
     }
 }
Ejemplo n.º 4
0
 private byte[] Protect(byte[] data)
 {
     //  ProtectedData throws UnsupportedPlatform exception, utilizing ManagedProtection directly from Mono
     return(ManagedProtection.Protect(data, this._additionalEntropy, DataProtectionScope.CurrentUser));
 }
Ejemplo n.º 5
0
 protected override byte [] Protect(byte [] data)
 => ManagedProtection.Protect(
     data,
     null,
     DataProtectionScope.CurrentUser);