/// <inheritdoc /> public byte[] Export(CryptographicPrivateKeyBlobType blobType) { try { return(this.key.Export(AsymmetricKeyAlgorithmProvider.GetPlatformKeyBlobType(blobType)).ToArray()); } catch (NotImplementedException ex) { throw new NotSupportedException(ex.Message, ex); } catch (ArgumentException ex) { // ArgumentException can be thrown when we don't have the private key, // or when the key can't be serialized using the requested format. // The first of these deserves an InvalidOperationException while // the second one deserves a NotSupportedException. But we can't clearly // discern each case from the exception. So we use internal state to assist. if (this.canExportPrivateKey) { // Exporting should work, so it must be an unsupported format. throw new NotSupportedException(ex.Message, ex); } else { // We can't have been expected to export regardless of the setting. throw new InvalidOperationException(ex.Message, ex); } } }
/// <inheritdoc /> public byte[] ExportPublicKey(CryptographicPublicKeyBlobType blobType) { try { return(this.key.ExportPublicKey(AsymmetricKeyAlgorithmProvider.GetPlatformKeyBlobType(blobType)).ToArray()); } catch (NotImplementedException ex) { throw new NotSupportedException(ex.Message, ex); } }