Configs.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using PCC.App.Security;
  2. using System.Security.Cryptography;
  3. namespace PCC.App.Tpm;
  4. public interface IPeerInfoProvider
  5. {
  6. public ICollection<ILocalPeerInfo> PeerInfo { get; }
  7. }
  8. public interface ILocalPeerInfo
  9. {
  10. //RSA PublicKey { get; }
  11. RSA PrivateKey { get; }
  12. string PeerId { get; }
  13. string Address { get; }
  14. int Port { get; }
  15. ICollection<IRemotePeerInfo> TrustedRemotePeers { get; }
  16. }
  17. public class LocalPeerInfo(byte[] publicKey, byte[] privateKey, string address, int port, ICollection<IRemotePeerInfo> remotePeers) : ILocalPeerInfo
  18. {
  19. //public RSA PublicKey { get; } = RsaUtility.FromPKCS1PublicKey(publicKey);
  20. public RSA PrivateKey { get; } = RsaUtility.FromPKCS1PublicKey(privateKey);
  21. public string PeerId { get; } = Convert.ToHexString(SHA256.HashData(publicKey));
  22. public string Address { get; } = address;
  23. public int Port { get; } = port;
  24. public ICollection<IRemotePeerInfo> TrustedRemotePeers { get; } = remotePeers;
  25. }
  26. public interface IRemotePeerInfo
  27. {
  28. RSA PublicKey { get; }
  29. string PeerId { get; }
  30. string Host { get; }
  31. int Port { get; }
  32. }
  33. public class RemotePeerInfo(byte[] publicKey, string host, int port) : IRemotePeerInfo
  34. {
  35. public RSA PublicKey { get; } = RsaUtility.FromPKCS1PublicKey(publicKey);
  36. public string PeerId { get; } = Convert.ToHexString(SHA256.HashData(publicKey));
  37. public string Host { get; } = host;
  38. public int Port { get; } = port;
  39. }