示例#1
0
def signProposal(proposal, entity, signersCert):
	import hashlib
	from ecdsa import util
	from ecdsa import VerifyingKey
	import binascii
	# Sign the proposal
	proposalBytes = proposal.SerializeToString()
	#print("Proposal Bytes = \n{0}\n\n".format(binascii.hexlify(bytearray(proposalBytes))))

	# calculate sha2_256 and dump for info only
	digest = hashlib.sha256(proposalBytes).digest()
	print("Proposal Bytes digest= \n{0}\n\n".format( binascii.hexlify(bytearray(digest))  ))
	signature = entity.sign(proposalBytes)
	# signature = signingKey.sign(proposalBytes, hashfunc=hashlib.sha256, sigencode=util.sigencode_der)

	#Verify the signature
	entity.verifySignature(signature=signature, signersCert=signersCert, data=proposalBytes)
	# vk = VerifyingKey.from_der(crypto.dump_publickey(crypto.FILETYPE_ASN1, signersCert.get_pubkey()))
	# assert vk.verify(signature, proposalBytes, hashfunc=hashlib.sha256, sigdecode=util.sigdecode_der), "Invalid signature!!"

	print("Proposal Bytes signature= \n{0}\n\n".format(binascii.hexlify(bytearray(signature))))
	print("")

	signedProposal = proposal_pb2.SignedProposal(proposalBytes=proposalBytes, signature=signature)
	return signedProposal
def signProposal(proposal, entity, signersCert):
	import binascii
	# Sign the proposal
	proposalBytes = proposal.SerializeToString()
	signature = entity.sign(proposalBytes)
	#Verify the signature
	entity.verifySignature(signature=signature, signersCert=signersCert, data=proposalBytes)
	# print("Proposal Bytes signature= \n{0}\n\n".format(binascii.hexlify(bytearray(signature))))
	signedProposal = proposal_pb2.SignedProposal(proposal_bytes=proposalBytes, signature=signature)
	return signedProposal