public static bool TryImport( Algorithm algorithm, ReadOnlySpan <byte> blob, KeyBlobFormat format, KeyFlags flags, out Key result) { if (algorithm == null) { throw Error.ArgumentNull_Algorithm(nameof(algorithm)); } SecureMemoryHandle keyHandle = null; byte[] publicKeyBytes = null; bool success = false; try { success = algorithm.TryImportKey(blob, format, out keyHandle, out publicKeyBytes); } finally { if (!success && keyHandle != null) { keyHandle.Dispose(); } } result = success ? new Key(algorithm, flags, keyHandle, publicKeyBytes) : null; return(success); }
public static Key Import( Algorithm algorithm, ReadOnlySpan <byte> blob, KeyBlobFormat format, KeyExportPolicies exportPolicy = KeyExportPolicies.None) { if (algorithm == null) { throw Error.ArgumentNull_Algorithm(nameof(algorithm)); } SecureMemoryHandle keyHandle = null; byte[] publicKeyBytes = null; bool success = false; try { success = algorithm.TryImportKey(blob, format, out keyHandle, out publicKeyBytes); } finally { if (!success && keyHandle != null) { keyHandle.Dispose(); } } if (!success) { throw Error.Format_InvalidBlob(); } return(new Key(algorithm, exportPolicy, keyHandle, publicKeyBytes)); }