Exemplo n.º 1
0
 public static Key KeyExchange(KeyTypes keyType, Key privateKey, Key publicKey)
 {
     if (keyType == KeyTypes.Ed25519)
     {
         return(Ed25519Key.KeyExchangeInternal(privateKey as Ed25519Key, publicKey as Ed25519Key));
     }
     throw new ArgumentException(string.Format("Key type not implemented {0}", keyType));
 }
Exemplo n.º 2
0
        public SigningTool(string ed25519KeyPath)
        {
            if (!File.Exists(ed25519KeyPath))
            {
                throw new ArgumentException("ed25519 Private Key file does not exist", nameof(ed25519KeyPath));
            }

            var key = Ed25519Key.FromFile(ed25519KeyPath);

            _privateKey = Key.Import(_algorithm, key.ToBytes(), KeyBlobFormat.PkixPrivateKey);
        }
Exemplo n.º 3
0
        public static Ed25519Key FromFile(this Ed25519Key key, string path)
        {
            if (!File.Exists(path))
            {
                throw new ArgumentException("Key file path is invalid", nameof(path));
            }

            var json = File.ReadAllText(path);

            if (string.IsNullOrEmpty(json))
            {
                throw new ArgumentException("Provided file contains no data", nameof(path));
            }

            return(JsonSerializer.Deserialize <Ed25519Key>(json));
        }
Exemplo n.º 4
0
            internal static Ed25519Key KeyExchangeInternal(Ed25519Key privateKey, Ed25519Key publicKey)
            {
                if (privateKey == null || !privateKey.IsPrivate)
                {
                    throw new ArgumentException("Invalid Private Key", nameof(privateKey));
                }

                if (publicKey == null)
                {
                    throw new ArgumentException("Invalid Public Key", nameof(privateKey));
                }

                var sharedKeyData = new byte[32];

                Ed25519.KeyExchange(new ArraySegment <byte>(sharedKeyData), publicKey.RawData, privateKey.RawData);

                return(new Ed25519Key(sharedKeyData));
            }
Exemplo n.º 5
0
 public Verifier(Ed25519Key publicKey)
 {
     _signatureTool = new SignatureTool(publicKey);
 }