Chaos.NaCl
Chaos.NaCl copied to clipboard
Using of _basePoint
i need to get public key using the _basePoint, but i see nowhere, u using it,
Please prove solution.
- Generating Random Privatekey.
- Generating Public Key using Privatekey and _basePoint
For montgomery form Curve25519 you can use MontgomeryCurve25519.GetPublicKey. Use a random 32 byte value as private key. Note that this twiddles some bits to match NaCl, so it doesn't work with computed scalars.
For Ed25519 you can use Ed25519.KeyPairFromSeed or (PublicKeyFromSeed and ExpandedPrivateKeyFromSeed) to generate a key-pair. Use a random 32 byte value as privateKeySeed.
Internally I'm using a specialized method for multiplying with the base point, which is about twice as fast as using a general purpose scalar multiplication routine and passing it the base point.
To generate those random 32 byte values you can use a function like:
public static byte[] GetRandomBytes(int length)
{
using(var rng = new RNGCryptoServiceProvider())
{
var bytes = new byte[length];
rng.GetBytes(bytes);
return bytes;
}
}
I didn't include this in my library because it's only available in some flavours of the .net framework.
@CodesInChaos , Thanks for your Help,
I got the required Result.
Have 2 more queries
- Regarding Creating Signature
- Regarding Verifying the Created Signature.
i am not able to get.
Please provide a solution
byte[] publicKey, privateKey;
Ed25519.KeyPairFromSeed(out publicKey, out privateKey, GetRandomBytes(32));
byte[] signature = Ed25519.Sign(message, privateKey);
bool isValid = Ed25519.Verify(signature, message, publicKey);