def testDerConversion(self): privateKey = PrivateKey() message = "This is a text message" signature1 = Ecdsa.sign(message, privateKey) der = signature1.toDer() signature2 = Signature.fromDer(der) self.assertEqual(signature1.r, signature2.r) self.assertEqual(signature1.s, signature2.s)
def testDerConversion(self): privateKey = PrivateKey() message = "This is a text message" signature1 = Ecdsa.sign(message, privateKey) der = signature1.toDer(withRecoveryId=True) signature2 = Signature.fromDer(der, recoveryByte=True) self.assertEqual(signature1.r, signature2.r) self.assertEqual(signature1.s, signature2.s) self.assertEqual(signature1.recoveryId, signature2.recoveryId)
def testVerifySignature(self): # openssl ec -in privateKey.pem -pubout -out publicKey.pem publicKeyPem = File.read("publicKey.pem") # openssl dgst -sha256 -sign privateKey.pem -out signature.binary message.txt signatureDer = File.read("signatureDer.txt", "rb") message = File.read("message.txt") publicKey = PublicKey.fromPem(publicKeyPem) signature = Signature.fromDer(string=signatureDer) self.assertTrue( Ecdsa.verify(message=message, signature=signature, publicKey=publicKey))