Exemple #1
0
        /// <summary>
        /// Create an ECDsaOpenSsl from an existing <see cref="IntPtr"/> whose value is an
        /// existing OpenSSL <c>EC_KEY*</c>.
        /// </summary>
        /// <remarks>
        /// This method will increase the reference count of the <c>EC_KEY*</c>, the caller should
        /// continue to manage the lifetime of their reference.
        /// </remarks>
        /// <param name="handle">A pointer to an OpenSSL <c>EC_KEY*</c></param>
        /// <exception cref="ArgumentException"><paramref name="handle" /> is invalid</exception>
        public ECDsaOpenSsl(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException(SR.Cryptography_OpenInvalidHandle, "handle");
            }

            SafeEcKeyHandle ecKeyHandle = SafeEcKeyHandle.DuplicateHandle(handle);

            int nid     = Interop.libcrypto.EcKeyGetCurveName(ecKeyHandle);
            int keySize = 0;

            for (int i = 0; i < s_supportedAlgorithms.Length; i++)
            {
                if (s_supportedAlgorithms[i].Nid == nid)
                {
                    keySize = s_supportedAlgorithms[i].KeySize;
                    break;
                }
            }
            if (keySize == 0)
            {
                string curveNameOid = Interop.libcrypto.OBJ_obj2txt_helper(Interop.libcrypto.OBJ_nid2obj(nid));
                throw new NotSupportedException(SR.Format(SR.Cryptography_UnsupportedEcKeyAlgorithm, curveNameOid));
            }

            // Set base.KeySize rather than this.KeySize to avoid an unnecessary Lazy<> allocation.
            base.KeySize = keySize;
            _key         = new Lazy <SafeEcKeyHandle>(() => ecKeyHandle);
        }
Exemple #2
0
            internal ECDiffieHellmanAndroidPublicKey(SafeEcKeyHandle ecKeyHandle)
            {
                ArgumentNullException.ThrowIfNull(ecKeyHandle);

                if (ecKeyHandle.IsInvalid)
                {
                    throw new ArgumentException(SR.Cryptography_OpenInvalidHandle, nameof(ecKeyHandle));
                }

                _key = new ECAndroid(ecKeyHandle.DuplicateHandle());
            }
Exemple #3
0
        /// <summary>
        /// Create an ECDsaOpenSsl from an existing <see cref="IntPtr"/> whose value is an
        /// existing OpenSSL <c>EC_KEY*</c>.
        /// </summary>
        /// <remarks>
        /// This method will increase the reference count of the <c>EC_KEY*</c>, the caller should
        /// continue to manage the lifetime of their reference.
        /// </remarks>
        /// <param name="handle">A pointer to an OpenSSL <c>EC_KEY*</c></param>
        /// <exception cref="ArgumentException"><paramref name="handle" /> is invalid</exception>
        public ECDsaOpenSsl(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException(SR.Cryptography_OpenInvalidHandle, nameof(handle));
            }

            SafeEcKeyHandle ecKeyHandle = SafeEcKeyHandle.DuplicateHandle(handle);

            SetKey(ecKeyHandle);
        }
Exemple #4
0
        /// <summary>
        /// Create an ECDsaOpenSsl from an existing <see cref="IntPtr"/> whose value is an
        /// existing OpenSSL <c>EC_KEY*</c>.
        /// </summary>
        /// <remarks>
        /// This method will increase the reference count of the <c>EC_KEY*</c>, the caller should
        /// continue to manage the lifetime of their reference.
        /// </remarks>
        /// <param name="handle">A pointer to an OpenSSL <c>EC_KEY*</c></param>
        /// <exception cref="ArgumentException"><paramref name="handle" /> is invalid</exception>
        public ECDsaOpenSsl(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException(SR.Cryptography_OpenInvalidHandle, nameof(handle));
            }

            SafeEcKeyHandle ecKeyHandle = SafeEcKeyHandle.DuplicateHandle(handle);

            _key         = new ECOpenSsl(ecKeyHandle);
            KeySizeValue = _key.KeySize;
        }
Exemple #5
0
        /// <summary>
        /// Create an ECDsaOpenSsl from an existing <see cref="IntPtr"/> whose value is an
        /// existing OpenSSL <c>EC_KEY*</c>.
        /// </summary>
        /// <remarks>
        /// This method will increase the reference count of the <c>EC_KEY*</c>, the caller should
        /// continue to manage the lifetime of their reference.
        /// </remarks>
        /// <param name="handle">A pointer to an OpenSSL <c>EC_KEY*</c></param>
        /// <exception cref="ArgumentException"><paramref name="handle" /> is invalid</exception>
        public ECDsaOpenSsl(IntPtr handle)
        {
            if (handle == IntPtr.Zero)
            {
                throw new ArgumentException(SR.Cryptography_OpenInvalidHandle, nameof(handle));
            }

            SafeEcKeyHandle ecKeyHandle = SafeEcKeyHandle.DuplicateHandle(handle);

            // Set base.KeySize rather than this.KeySize to avoid an unnecessary Lazy<> allocation.
            base.KeySize = GetKeySize(ecKeyHandle);
            _key         = new Lazy <SafeEcKeyHandle>(() => ecKeyHandle);
        }
Exemple #6
0
 internal ECDsaAndroid(SafeEcKeyHandle ecKeyHandle)
 {
     _key = new ECAndroid(ecKeyHandle.DuplicateHandle());
     ForceSetKeySize(_key.KeySize);
 }
 internal ECDiffieHellmanAndroid(SafeEcKeyHandle ecKeyHandle)
 {
     _key         = new ECAndroid(ecKeyHandle.DuplicateHandle());
     KeySizeValue = _key.KeySize;
 }