rsasign.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # file: rsasign.py
  2. import cyassl
  3. # start Random Number Generator
  4. rng = cyassl.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 = cyassl.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 = cyassl.byteArray(128) # 128 allows 1024 bit private key
  15. signStr = cyassl.byteArray(25) # input can't be larger then key size
  16. # 64 for 512 bit 128 for 1024 bit
  17. cyassl.FillSignStr(signStr, "Everybody gets Friday off", 25)
  18. # Do RSA Sign
  19. signedSize = cyassl.RsaSSL_Sign(signStr, 25, signOutput, 128, key, rng)
  20. # Show output
  21. print "Signed Size = ", signedSize, " signed array = ", cyassl.cdata(signOutput, signedSize)
  22. # let's verify this worked
  23. signVerify = cyassl.byteArray(signedSize)
  24. verifySize = cyassl.RsaSSL_Verify(signOutput, signedSize, signVerify, signedSize, key)
  25. print "Verify Size = ", verifySize, " verify array = ", cyassl.cdata(signVerify, verifySize)