/// <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); }
internal ECDiffieHellmanAndroidPublicKey(SafeEcKeyHandle ecKeyHandle) { ArgumentNullException.ThrowIfNull(ecKeyHandle); if (ecKeyHandle.IsInvalid) { throw new ArgumentException(SR.Cryptography_OpenInvalidHandle, nameof(ecKeyHandle)); } _key = new ECAndroid(ecKeyHandle.DuplicateHandle()); }
/// <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); }
/// <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; }
/// <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); }
internal ECDsaAndroid(SafeEcKeyHandle ecKeyHandle) { _key = new ECAndroid(ecKeyHandle.DuplicateHandle()); ForceSetKeySize(_key.KeySize); }
internal ECDiffieHellmanAndroid(SafeEcKeyHandle ecKeyHandle) { _key = new ECAndroid(ecKeyHandle.DuplicateHandle()); KeySizeValue = _key.KeySize; }