private void ThrowIfDisposed()
            {
                SecKeyPair?current = _keys;

                if (current != null && current.PublicKey == null)
                {
                    throw new ObjectDisposedException(nameof(RSA));
                }
            }
        private void SetKey(SecKeyPair keyPair)
        {
            ThrowIfDisposed();

            SecKeyPair?current = _keys;

            _keys = keyPair;
            current?.Dispose();
        }
        internal SecKeyPair GetOrGenerateKeys(int keySizeInBits)
        {
            ThrowIfDisposed();

            SecKeyPair?current = _keys;

            if (current != null)
            {
                return(current);
            }

            return(GenerateKey(keySizeInBits));
        }
            private void SetKey(SecKeyPair newKeyPair)
            {
                ThrowIfDisposed();

                SecKeyPair?current = _keys;

                _keys = newKeyPair;
                current?.Dispose();

                if (newKeyPair != null)
                {
                    KeySizeValue = Interop.AppleCrypto.GetSimpleKeySizeInBits(newKeyPair.PublicKey);
                }
            }
            protected override void Dispose(bool disposing)
            {
                if (disposing)
                {
                    if (_keys != null)
                    {
                        _keys.Dispose();
                        _keys = null;
                    }

                    _disposed = true;
                }

                base.Dispose(disposing);
            }
            internal SecKeyPair GetKeys()
            {
                ThrowIfDisposed();

                SecKeyPair?current = _keys;

                if (current != null)
                {
                    return(current);
                }

                // macOS 10.11 and macOS 10.12 declare DSA invalid for key generation.
                // Rather than write code which might or might not work, returning
                // (OSStatus)-4 (errSecUnimplemented), just make the exception occur here.
                //
                // When the native code can be verified, then it can be added.
                throw new PlatformNotSupportedException(SR.Cryptography_DSA_KeyGenNotSupported);
            }
            internal SecKeyPair GetKeys()
            {
                ThrowIfDisposed();
                SecKeyPair?current = _keys;

                if (current != null)
                {
                    return(current);
                }

                SafeSecKeyRefHandle publicKey;
                SafeSecKeyRefHandle privateKey;

                Interop.AppleCrypto.RsaGenerateKey(KeySizeValue, out publicKey, out privateKey);

                current = SecKeyPair.PublicPrivatePair(publicKey, privateKey);
                _keys   = current;
                return(current);
            }
 internal void DisposeKey()
 {
     _keys?.Dispose();
     _keys = null;
 }