private static KeyPair GenerateEd25519KeyPair() { using (var pair = Sodium.PublicKeyAuth.GenerateKeyPair()) { var pk = new Ed25519PublicKey(pair.PublicKey); var sk = new Ed25519PrivateKey(pair.PrivateKey, pair.PublicKey); return(new KeyPair(sk, pk)); } }
/// <summary> /// Deserialize a private key from a stream /// </summary> /// <param name="stream">stream to read from</param> /// <returns>private key</returns> public static PrivateKey Unmarshal(Stream stream) { var pb = Serializer.Deserialize <PrivateKeyContract>(stream); switch (pb.Type) { case KeyType.RSA: return(RsaPrivateKey.Unmarshal(pb.Data)); case KeyType.Ed25519: return(Ed25519PrivateKey.Unmarshal(pb.Data)); default: throw new Exception("Bad key type"); } }