예제 #1
0
        print(e)

    address = Nakasendo.BSVAddress.initFromAddress(addressStrValid)
    print("Address: %s has valid = %s" %
          (addressStrValid, bool(address.valid)))

    #creata an Asmkey ..
    #use ECDSA to sign
    #use Nakasendo to verify
    AliceKey = Nakasendo.ECKey256K1(asHex=True)
    ecdsaPubKey = int(AliceKey.priKey, 16) * G
    print('Public Key for ecdsa verification %s' % ecdsaPubKey)
    points = ecdsaPubKey
    xval = hex(ecdsaPubKey.x())[2:]
    yval = hex(ecdsaPubKey.y())[2:]
    pempubkey = Nakasendo.pubKeyHexPtasPem(xval, yval)
    pubkeytest = ecdsa.ecdsa.Public_key(G, ecdsaPubKey)
    privkeytest = ecdsa.ecdsa.Private_key(pubkeytest, int(AliceKey.priKey, 16))

    #print ('private key %s' % secret.value )

    #ecdsa_sig = privkeytest.sign(int(Hm.value,16),int(inv_k.value,16))

    #signature = ecdsa.util.sigencode_der_canonize(ecdsa_sig.r, ecdsa_sig.s,int(modulo_n.value,16))
    message = 'Im a message and Im about to be hashed'

    print('Private Key in Hex %s \n Public Key Hex %s' %
          (AliceKey.priKey, AliceKey.pubKey))
    hashedT = Nakasendo.hash256(message)
    print(hashedT)
    ecdsa_sig = privkeytest.sign(int(hashedT.value, 16),
예제 #2
0
    message = sys.argv[4]

    dersigStr = None
    if (len(sys.argv) == 6):
        dersigStr = sys.argv[5]

    print('[%s, %s] \n pubkey %s \nmessage = %s' %
          (sigRStr, sigSStr, pubKeyStr, message))
    # create an ECPoint
    pt = Nakasendo.ECPoint()
    pt.value = pubKeyStr
    #print(pt.GetAffineCoOrdinates())

    coords = pt.GetAffineCoOrdinates()

    pempubkey = Nakasendo.pubKeyHexPtasPem(coords[0], coords[1])
    print(pempubkey)
    print('verify the pem format')
    pubKeyStrValidate = Nakasendo.pubKeyPEMasHex(pempubkey, True)
    #print(pubKeyStrValidate)
    # get the affine co-ordinates
    # get pem format

    valPem = Nakasendo.verify(message, pempubkey, sigRStr, sigSStr)
    if (valPem == True):
        print(
            'Calculated signature verified with calculated PEM & call to verify'
        )
    else:
        print('Failed to verify with calculated PEM')