Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Signature verification
#11
If you need to read the public key from string, you have to remove line 13.
And at line 14 put the string.
Reply
#12
(Nov-20-2018, 06:25 PM)saisankalpj Wrote:
(Nov-20-2018, 06:03 PM)gontajones Wrote: Hummm...my bad about saying that you were mentioning a private key, sorry.

This is a RSA public key? It should be.
Try with:
-----BEGIN RSA PUBLIC KEY----- ... -----END RSA PUBLIC KEY-----

Ok will check tomorrow and tell u ? Any other suggestion from you?

This is also not working .After adding -----BEGIN RSA PUBLIC KEY----- ... -----END RSA PUBLIC KEY----- also i am getting False
Reply
#13
1 - Are you passing the params of verify_sign() as string?
2 - If so, did you change lines 13 and 14?
3 - Another thing is the base64 encoding, have you encoded the signature and data?

Please, answer every question for us to keep helping you.
Reply
#14
(Nov-21-2018, 07:42 AM)gontajones Wrote: 1 - Are you passing the params of verify_sign() as string?
2 - If so, did you change lines 13 and 14?
3 - Another thing is the base64 encoding, have you encoded the signature and data?

Please, answer every question for us to keep helping you.

1-yes i am passing it as string
2-pub_key = "-----BEGIN RSA PUBLIC KEY-----\n" + public_key_loc + "\n-----END RSA PUBLIC KEY-----".i have changed the lines like these
3-i was doing base64decode.i have checked even with base64 encode
all seem to return false
Reply
#15
Here is working well.
Try these parameters:
- pub_key: string
- signature: string
- data: string

def verify_sign(public_key_string, signature, data):
    from Crypto.PublicKey import RSA
    from Crypto.Signature import PKCS1_v1_5
    from Crypto.Hash import SHA256
    rsakey = RSA.importKey(public_key_string)
    signer = PKCS1_v1_5.new(rsakey)
    digest = SHA256.new()
    digest.update(data)
    if signer.verify(digest, signature):
        return True
    return False
and obviously your key must be generated using RSA.
Reply
#16
(Nov-21-2018, 10:03 AM)gontajones Wrote: Here is working well.
Try to this, it uses:
- pub_key: string
- signature: string
- data: string

def verify_sign(public_key_string, signature, data):
    from Crypto.PublicKey import RSA
    from Crypto.Signature import PKCS1_v1_5
    from Crypto.Hash import SHA256
    rsakey = RSA.importKey(public_key_string)
    signer = PKCS1_v1_5.new(rsakey)
    digest = SHA256.new()
    digest.update(data)
    if signer.verify(digest, signature):
        return True
    return False
and obviously your key must be generated using RSA.
Can i use SHA512.new() instead of SHA256.new()
Reply
#17
I really don't know that. =/
Did you try it?
It keeps returning False?
Reply
#18
(Nov-21-2018, 06:13 PM)gontajones Wrote: I really don't know that. =/
Did you try it?
It keeps returning False?

Yes it keeps returning false
Reply
#19
So I think your best shot will be sharing all these info (pub, sign, data).
Then we'll be able to test and see what's really going on.
If they are not "private", off course.
Reply
#20
(Nov-22-2018, 10:32 AM)gontajones Wrote: So I think your best shot will be sharing all these info (pub, sign, data).
Then we'll be able to test and see what's really going on.
If they are not "private", off course.

I cant share it is confidential
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can I get Python Bulk Email Verification Script With API? zainalee 1 3,059 Jun-06-2021, 09:19 AM
Last Post: snippsat
Video Python Bulk Email Verification Script With API Aj1128 0 3,122 Nov-28-2020, 11:38 AM
Last Post: Aj1128
  List items verification for Integer type vintysaw 4 3,822 Jan-17-2020, 01:56 PM
Last Post: perfringo
  Remove Email Signature NewBeie 4 11,146 Jan-01-2020, 06:44 PM
Last Post: PythonPaul2016
  [cryptography.io] How to convert DER signature to ECDSA fstefanov 1 3,938 Jul-04-2019, 08:59 AM
Last Post: fstefanov
  Signature verification saisankalpj 8 6,738 Nov-20-2018, 09:32 AM
Last Post: saisankalpj
  With Python I cannot calculate an AWS signature for Rest APIs Johno 4 7,797 Oct-06-2016, 11:05 AM
Last Post: Johno

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020