Tempest.RSACrypto.ExportKey C# (CSharp) Method

ExportKey() public method

public ExportKey ( bool includePrivate ) : RSAAsymmetricKey
includePrivate bool
return RSAAsymmetricKey
        public RSAAsymmetricKey ExportKey(bool includePrivate)
        {
            return new RSAAsymmetricKey (this.rsaCrypto.ExportParameters (includePrivate));
        }

Usage Example

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);
            });
        }
All Usage Examples Of Tempest.RSACrypto::ExportKey