示例#1
0
        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);
        }
示例#2
0
文件: Key.cs 项目: cwharris/nsec
        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));
        }