public void RoundTripTest() { var AliceKeys = new SigningKeyPair(new PrivateSecretKey(K_PRI_ALICE), new PublicKey(K_PUB_ALICE)); var pen = new Signer(AliceKeys.Secret); var signature = pen.Sign(MESSAGE); Assert.IsTrue(signature.Verify(MESSAGE, AliceKeys.Public)); }
/// <inheritdoc/> public override SigningKeyPair GenerateKeyPair() { SigningKeyPair keyPair = new SigningKeyPair(new byte[32],new byte[64]); if(NativeLibsodium.crypto_sign_keypair(keyPair.publicKey,keyPair.secretKey) != 0) throw new Exception("Could not create new KeyPair"); keyPair.algorythm = this; return keyPair; }
public void RoundTripTest_WrongMessage() { var AliceKeys = new SigningKeyPair(new PrivateSecretKey(K_PRI_ALICE), new PublicKey(K_PUB_ALICE)); var BobsPubKey = new PublicKey(K_PUB_BOB); var pen = new Signer(AliceKeys.Secret); var signature = pen.Sign(MESSAGE); Assert.IsFalse(signature.Verify(MESSAGE_CHANGED, BobsPubKey)); }
public void NullParamterTest() { var keyPair = new SigningKeyPair(new PrivateSecretKey(K_PRI_ALICE), new PublicKey(K_PUB_ALICE)); Assert.ThrowsException <ArgumentNullException>(() => new Signer(null)); var pen = new Signer(keyPair.Secret); Assert.ThrowsException <ArgumentNullException>(() => pen.Sign(str: null)); Assert.ThrowsException <ArgumentNullException>(() => pen.Sign(str: "")); Assert.ThrowsException <ArgumentNullException>(() => pen.Sign(data: null)); Assert.ThrowsException <ArgumentNullException>(() => pen.Sign(data: new byte[0])); }
public void RoundTripTest_Tampered() { var AliceKeys = new SigningKeyPair(new PrivateSecretKey(K_PRI_ALICE), new PublicKey(K_PUB_ALICE)); var pen = new Signer(AliceKeys.Secret); var signature = pen.Sign(MESSAGE); for (int i = 0; i < 5; i++) { signature.Bytes[i] = 0; } Assert.IsFalse(signature.Verify(MESSAGE, AliceKeys.Public)); }