rsasign.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # file: rsasign.py
  2. import wolfssl
  3. # start Random Number Generator
  4. rng = wolfssl.GetRng()
  5. if rng == None:
  6. print "Couldn't get an RNG"
  7. exit(-1)
  8. # load RSA private key in DER format
  9. key = wolfssl.GetRsaPrivateKey("../certs/client-key.der")
  10. if key == None:
  11. print "Couldn't load DER private key file"
  12. exit(-1)
  13. # Make byte Arrays and fill input
  14. signOutput = wolfssl.byteArray(128) # 128 allows 1024 bit private key
  15. signStr = wolfssl.byteArray(25) # input can't be larger then key size
  16. # 64 for 512 bit 128 for 1024 bit
  17. wolfssl.FillSignStr(signStr, "Everybody gets Friday off", 25)
  18. # Do RSA Sign
  19. signedSize = wolfssl.RsaSSL_Sign(signStr, 25, signOutput, 128, key, rng)
  20. # Show output
  21. print "Signed Size = ", signedSize, " signed array = ", wolfssl.cdata(signOutput, signedSize)
  22. # let's verify this worked
  23. signVerify = wolfssl.byteArray(signedSize)
  24. verifySize = wolfssl.RsaSSL_Verify(signOutput, signedSize, signVerify, signedSize, key)
  25. print "Verify Size = ", verifySize, " verify array = ", wolfssl.cdata(signVerify, verifySize)