Key.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Renci.SshNet.Common;
  2. using Renci.SshNet.Security.Cryptography;
  3. namespace Renci.SshNet.Security
  4. {
  5. /// <summary>
  6. /// Base class for asymmetric cipher algorithms.
  7. /// </summary>
  8. public abstract class Key
  9. {
  10. /// <summary>
  11. /// Gets the default digital signature implementation for this key.
  12. /// </summary>
  13. protected internal abstract DigitalSignature DigitalSignature { get; }
  14. /// <summary>
  15. /// Gets the public key.
  16. /// </summary>
  17. /// <value>
  18. /// The public.
  19. /// </value>
  20. public abstract BigInteger[] Public { get; }
  21. /// <summary>
  22. /// Gets the length of the key.
  23. /// </summary>
  24. /// <value>
  25. /// The length of the key.
  26. /// </value>
  27. public abstract int KeyLength { get; }
  28. /// <summary>
  29. /// Gets or sets the key comment.
  30. /// </summary>
  31. public string Comment { get; set; }
  32. /// <summary>
  33. /// Signs the specified data with the key.
  34. /// </summary>
  35. /// <param name="data">The data to sign.</param>
  36. /// <returns>
  37. /// Signed data.
  38. /// </returns>
  39. public byte[] Sign(byte[] data)
  40. {
  41. return DigitalSignature.Sign(data);
  42. }
  43. /// <summary>
  44. /// Verifies the signature.
  45. /// </summary>
  46. /// <param name="data">The data to verify.</param>
  47. /// <param name="signature">The signature to verify against.</param>
  48. /// <returns><see langword="true"/> is signature was successfully verifies; otherwise <see langword="false"/>.</returns>
  49. public bool VerifySignature(byte[] data, byte[] signature)
  50. {
  51. return DigitalSignature.Verify(data, signature);
  52. }
  53. }
  54. }