From f2c21d419f3e9778ba72218c93ceb0aa39eb8412 Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Sun, 31 Jan 2016 11:36:42 +0100 Subject: [PATCH] Delete RSADigitalSignature.cs --- .../Cryptography/RSADigitalSignature.cs | 115 ------------------ 1 file changed, 115 deletions(-) delete mode 100644 Renci.SshClient/Renci.SshNet/Security/Cryptography/RSADigitalSignature.cs diff --git a/Renci.SshClient/Renci.SshNet/Security/Cryptography/RSADigitalSignature.cs b/Renci.SshClient/Renci.SshNet/Security/Cryptography/RSADigitalSignature.cs deleted file mode 100644 index 8da13ddf5..000000000 --- a/Renci.SshClient/Renci.SshNet/Security/Cryptography/RSADigitalSignature.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Security.Cryptography; -using Renci.SshNet.Common; - -namespace Renci.SshNet.Security.Cryptography -{ - /// - /// Implements RSAdigital signature algorithm. - /// - public class RSADigitalSignature : DigitalSignature - { - private HashAlgorithm _hash; - private RSACipher _cipher; - - /// - /// Initializes a new instance of the class. - /// - /// The key. - public RSADigitalSignature(RSAPublicKey key) - { - this._hash = new SHA1Hash(); - this._cipher = new RSACipher(this._hash, key); - } - - /// - /// Verifies the signature. - /// - /// The input. - /// The signature. - /// - public override bool VerifySignature(byte[] input, byte[] signature) - { - var sig = this._cipher.Transform(signature); - - // TODO: Ensure that only 1 or 2 types are supported - var position = 1; - while (position < sig.Length && sig[position] != 0) - position++; - position++; - - - var sig1 = new byte[sig.Length - position]; - - Array.Copy(sig, position, sig1, 0, sig1.Length); - - var hashData = this._hash.ComputeHash(input); - - var expected = DerEncode(hashData); - - if (expected.Count != sig1.Length) - return false; - - for (int i = 0; i < expected.Count; i++) - { - if (expected[i] != sig1[i]) - return false; - } - - return true; - } - - /// - /// Creates the signature. - /// - /// The input. - /// - public override byte[] CreateSignature(byte[] input) - { - // Calculate hash value - var hashData = this._hash.ComputeHash(input); - - // Calculate DER string - - // Resolve algorithm identifier - var dd = DerEncode(hashData); - - // Calculate signature - var rsaInputBlockSize = new byte[255]; - rsaInputBlockSize[0] = 0x01; - for (int i = 1; i < rsaInputBlockSize.Length - dd.Count - 1; i++) - { - rsaInputBlockSize[i] = 0xFF; - } - - Array.Copy(dd.ToArray(), 0, rsaInputBlockSize, rsaInputBlockSize.Length - dd.Count, dd.Count); - - var input1 = new BigInteger(rsaInputBlockSize.Reverse().ToArray()); - - return this._cipher.Transform(input1).ToByteArray().Reverse().TrimLeadingZero().ToArray(); - } - - private static List DerEncode(byte[] hashData) - { - // TODO: Replace with algorithm code - var algorithm = new byte[] { 6, 5, 43, 14, 3, 2, 26 }; - var algorithmParams = new byte[] { 5, 0 }; - - var dd = new List(algorithm); - dd.AddRange(algorithmParams); - dd.Insert(0, (byte)dd.Count); - dd.Insert(0, 48); - - dd.Add(4); - dd.Add((byte)hashData.Length); - dd.AddRange(hashData); - - dd.Insert(0, (byte)dd.Count); - dd.Insert(0, 48); - return dd; - } - } -}