Exemplo n.º 1
0
        public override void ImportEncryptedPkcs8PrivateKey(
            ReadOnlySpan <byte> passwordBytes,
            ReadOnlySpan <byte> source,
            out int bytesRead)
        {
            CngPkcs8.Pkcs8Response response = CngPkcs8.ImportEncryptedPkcs8PrivateKey(
                passwordBytes,
                source,
                out int localRead);

            ProcessPkcs8Response(response);
            bytesRead = localRead;
        }
Exemplo n.º 2
0
            private void AcceptImport(CngPkcs8.Pkcs8Response response)
            {
                SafeNCryptKeyHandle keyHandle = response.KeyHandle;

                _key.SetHandle(
                    keyHandle,
                    CngKeyLite.GetPropertyAsString(
                        keyHandle,
                        CngKeyLite.KeyPropertyName.Algorithm,
                        CngPropertyOptions.None));

                ForceSetKeySize(_key.KeySize);
            }
Exemplo n.º 3
0
        public override void ImportEncryptedPkcs8PrivateKey(
            ReadOnlySpan <char> password,
            ReadOnlySpan <byte> source,
            out int bytesRead)
        {
            ThrowIfDisposed();
            CngPkcs8.Pkcs8Response response = CngPkcs8.ImportEncryptedPkcs8PrivateKey(
                password,
                source,
                out int localRead);

            ProcessPkcs8Response(response);
            bytesRead = localRead;
        }
        private void ProcessPkcs8Response(CngPkcs8.Pkcs8Response response)
        {
            // Wrong algorithm?
            switch (response.GetAlgorithmGroup())
            {
            // CNG ECDH and ECDSA keys can both do ECDSA.
            case BCryptNative.AlgorithmName.ECDsa:
            case BCryptNative.AlgorithmName.ECDH:
                AcceptImport(response);
                return;
            }

            response.FreeKey();
            throw new CryptographicException(SR.Cryptography_NotValidPublicOrPrivateKey);
        }
Exemplo n.º 5
0
 private void AcceptImport(CngPkcs8.Pkcs8Response response)
 {
     Key = response.Key;
 }
Exemplo n.º 6
0
            private void AcceptImport(CngPkcs8.Pkcs8Response response)
            {
                SafeNCryptKeyHandle keyHandle = response.KeyHandle;

                SetKeyHandle(keyHandle);
            }