Пример #1
0
        private void SetupValidKeyInfo()
        {
            keyInfoWrapper.Setup(k => k.GetPublicKeyInfo(It.IsAny <byte[]>()))
            .Returns <byte[]>(content =>
            {
                var wrapper = new KeyInfoWrapper();
                return(wrapper.GetPublicKeyInfo(content));
            });

            keyInfoWrapper.Setup(k => k.GetPrivateKeyInfo(It.IsAny <byte[]>()))
            .Returns <byte[]>(content =>
            {
                var wrapper = new KeyInfoWrapper();
                return(wrapper.GetPrivateKeyInfo(content));
            });
        }
        public IAsymmetricKey GetPrivateKey(byte[] keyContent)
        {
            PrivateKeyInfo privateKeyInfo;

            try
            {
                privateKeyInfo = keyInfoWrapper.GetPrivateKeyInfo(keyContent);
            }
            catch (Exception exception) when(exception is ArgumentException ||
                                             exception is InvalidCastException)
            {
                throw new CryptographicException("Private key is not valid.");
            }

            return(GetKey(keyContent, privateKeyInfo.PrivateKeyAlgorithm.Algorithm.Id, AsymmetricKeyType.Private));
        }