Example #1
0
        public IAsymmetricKey GetAsDer(string sshKey)
        {
            string[] contentLines;
            if (sshKey.StartsWith("---- BEGIN SSH2 PUBLIC KEY ----"))
            {
                contentLines = sshKey.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
                IEnumerable <string> keyContent = contentLines.Where(line => base64.IsBase64(line));
                string key = string.Concat(keyContent);

                return(sshKeyProvider.GetKeyFromSsh(key));
            }

            contentLines = sshKey.Split(' ');
            return(sshKeyProvider.GetKeyFromSsh(contentLines[1]));
        }
        public void VerifySignature(ApplicationArguments arguments)
        {
            ReadKeyFromFileCommand readPublicKeyFromFile = fileCommandProvider.GetReadPublicKeyFromFileCommand(arguments.PublicKeyPath);

            commandExecutor.Execute(readPublicKeyFromFile);

            byte[] contentToVerify;
            if (arguments.HasFileInput)
            {
                ReadFileCommand <byte[]> readFileToVerify = fileCommandProvider.GetReadFileCommand <byte[]>(arguments.FileInput);
                commandExecutor.Execute(readFileToVerify);
                contentToVerify = readFileToVerify.Result;
            }
            else
            {
                contentToVerify = encoding.GetBytes(arguments.Input);
            }

            byte[] signatureToVerify;
            if (base64.IsBase64(arguments.Signature))
            {
                signatureToVerify = base64.FromBase64String(arguments.Signature);
            }
            else
            {
                ReadFileCommand <byte[]> readSignatureToVerify = fileCommandProvider.GetReadFileCommand <byte[]>(arguments.Signature);
                commandExecutor.Execute(readSignatureToVerify);

                string base64Signature = encoding.GetString(readSignatureToVerify.Result);
                signatureToVerify = base64.FromBase64String(base64Signature);
            }

            VerifySignatureCommand verifySignature = signatureCommandProvider.GetVerifySignatureCommand(readPublicKeyFromFile.Result, contentToVerify, signatureToVerify);

            commandExecutor.Execute(verifySignature);
        }