예제 #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));
        }