ExportKey() public method

public ExportKey ( bool includePrivate ) : RSAAsymmetricKey
includePrivate bool
return RSAAsymmetricKey
Beispiel #1
0
        public static Task<IAsymmetricKey> LoadKey(string path)
        {
            if (path == null)
                throw new ArgumentNullException ("path");

            return Task<IAsymmetricKey>.Factory.StartNew (() =>
            {
                if (!File.Exists (path) || new FileInfo (path).Length == 0)
                {
                    var crypto = new RSACrypto();
                    var key = crypto.ExportKey (includePrivate: true);

                    Directory.CreateDirectory (Path.GetDirectoryName (path));
                    using (var fstream = File.OpenWrite (path))
                    {
                        var writer = new StreamValueWriter (fstream);
                        key.Serialize (null, writer);
                    }

                    return key;
                }

                var reader = new BufferValueReader (File.ReadAllBytes (path));
                return new RSAAsymmetricKey (null, reader);
            });
        }
Beispiel #2
0
 public static Task StartAsync()
 {
     return Task.Run (() => {
         var crypto = new RSACrypto();
         return crypto.ExportKey (true);
     }).ContinueWith (t => StartAsync (t.Result), TaskScheduler.Default).Unwrap();
 }