Exemple #1
0
 internal static ReadOnlyMemory <byte> ReadSubjectPublicKeyInfo(
     ReadOnlyMemory <byte> source,
     out int bytesRead)
 {
     return(KeyFormatHelper.ReadSubjectPublicKeyInfo(
                s_validOids,
                source,
                out bytesRead));
 }
Exemple #2
0
 internal static void ReadSubjectPublicKeyInfo(
     ReadOnlySpan <byte> source,
     out int bytesRead,
     out ECParameters key)
 {
     KeyFormatHelper.ReadSubjectPublicKeyInfo <ECParameters>(
         s_validOids,
         source,
         FromECPublicKey,
         out bytesRead,
         out key);
 }
Exemple #3
0
        /// <summary>
        /// Imports the public key from an X.509 SubjectPublicKeyInfo structure after decryption,
        /// replacing the keys for this object
        /// </summary>
        /// <param name="source">The bytes of an X.509 SubjectPublicKeyInfo structure in the ASN.1-DER encoding.</param>
        /// <param name="bytesRead">
        /// When this method returns, contains a value that indicates the number
        /// of bytes read from <paramref name="source" />. This parameter is treated as uninitialized.
        /// </param>
        /// <exception cref="NotSupportedException">
        /// A derived class has not provided an implementation for <see cref="ImportParameters" />.
        /// </exception>
        /// <exception cref="CryptographicException">
        /// <p>
        ///   The contents of <paramref name="source" /> do not represent an
        ///   ASN.1-DER-encoded X.509 SubjectPublicKeyInfo structure.
        /// </p>
        /// <p>-or-</p>
        /// <p>
        ///   The contents of <paramref name="source" /> indicate the key is for an algorithm
        /// other than the algorithm represented by this instance.
        /// </p>
        /// <p>-or-</p>
        /// <p>
        ///   The contents of <paramref name="source" /> represent the key in a format that is not supported.
        /// </p>
        /// <p>-or-</p>
        /// <p>The algorithm-specific key import failed.</p>
        /// </exception>
        /// <remarks>
        /// This method only supports the binary (DER) encoding of SubjectPublicKeyInfo.
        /// If the value is Base64-encoded, the caller must Base64-decode the contents before calling this method.
        /// If this value is PEM-encoded, <see cref="ImportFromPem" /> should be used.
        /// </remarks>
        public override void ImportSubjectPublicKeyInfo(
            ReadOnlySpan <byte> source,
            out int bytesRead)
        {
            KeyFormatHelper.ReadSubjectPublicKeyInfo <ECParameters>(
                s_validOids,
                source,
                EccKeyFormatHelper.FromECPublicKey,
                out int localRead,
                out ECParameters key);

            ImportParameters(key);
            bytesRead = localRead;
        }
Exemple #4
0
        public override unsafe void ImportSubjectPublicKeyInfo(ReadOnlySpan <byte> source, out int bytesRead)
        {
            fixed(byte *ptr = &MemoryMarshal.GetReference(source))
            {
                using (MemoryManager <byte> manager = new PointerMemoryManager <byte>(ptr, source.Length))
                {
                    ReadOnlyMemory <byte> pkcs1 = KeyFormatHelper.ReadSubjectPublicKeyInfo(
                        s_validOids,
                        manager.Memory,
                        out int localRead);

                    ImportRSAPublicKey(pkcs1.Span, out _);
                    bytesRead = localRead;
                }
            }
        }