|
|
@@ -10,7 +10,6 @@ namespace Renci.SshNet.Security.Cryptography
|
|
|
public abstract class CipherDigitalSignature : DigitalSignature
|
|
|
{
|
|
|
private readonly AsymmetricCipher _cipher;
|
|
|
-
|
|
|
private readonly ObjectIdentifier _oid;
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -18,13 +17,13 @@ namespace Renci.SshNet.Security.Cryptography
|
|
|
/// </summary>
|
|
|
/// <param name="oid">The object identifier.</param>
|
|
|
/// <param name="cipher">The cipher.</param>
|
|
|
- public CipherDigitalSignature(ObjectIdentifier oid, AsymmetricCipher cipher)
|
|
|
+ protected CipherDigitalSignature(ObjectIdentifier oid, AsymmetricCipher cipher)
|
|
|
{
|
|
|
if (cipher == null)
|
|
|
throw new ArgumentNullException("cipher");
|
|
|
|
|
|
- this._cipher = cipher;
|
|
|
- this._oid = oid;
|
|
|
+ _cipher = cipher;
|
|
|
+ _oid = oid;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -37,8 +36,8 @@ namespace Renci.SshNet.Security.Cryptography
|
|
|
/// </returns>
|
|
|
public override bool Verify(byte[] input, byte[] signature)
|
|
|
{
|
|
|
- var encryptedSignature = this._cipher.Decrypt(signature);
|
|
|
- var hashData = this.Hash(input);
|
|
|
+ var encryptedSignature = _cipher.Decrypt(signature);
|
|
|
+ var hashData = Hash(input);
|
|
|
var expected = DerEncode(hashData);
|
|
|
return expected.SequenceEqual(encryptedSignature);
|
|
|
}
|
|
|
@@ -53,12 +52,12 @@ namespace Renci.SshNet.Security.Cryptography
|
|
|
public override byte[] Sign(byte[] input)
|
|
|
{
|
|
|
// Calculate hash value
|
|
|
- var hashData = this.Hash(input);
|
|
|
+ var hashData = Hash(input);
|
|
|
|
|
|
// Calculate DER string
|
|
|
var derEncodedHash = DerEncode(hashData);
|
|
|
|
|
|
- return this._cipher.Encrypt(derEncodedHash).TrimLeadingZero().ToArray();
|
|
|
+ return _cipher.Encrypt(derEncodedHash).TrimLeadingZero().ToArray();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
@@ -75,15 +74,13 @@ namespace Renci.SshNet.Security.Cryptography
|
|
|
/// <returns>DER Encoded byte array</returns>
|
|
|
protected byte[] DerEncode(byte[] hashData)
|
|
|
{
|
|
|
- var data = new DerData();
|
|
|
-
|
|
|
var alg = new DerData();
|
|
|
- alg.Write(this._oid);
|
|
|
+ alg.Write(_oid);
|
|
|
alg.WriteNull();
|
|
|
|
|
|
+ var data = new DerData();
|
|
|
data.Write(alg);
|
|
|
data.Write(hashData);
|
|
|
-
|
|
|
return data.Encode();
|
|
|
}
|
|
|
}
|