Generate a signature for string using the `sign_algo` and `RSA` algorithms
(message, pem_private, pem_passphrase="" , sign_algo="SHA384")
| 240 | return run |
| 241 | |
| 242 | def sign_string(message, pem_private, pem_passphrase="" , sign_algo="SHA384"): |
| 243 | """ |
| 244 | Generate a signature for string using the `sign_algo` and `RSA` algorithms |
| 245 | """ |
| 246 | from Crypto.PublicKey import RSA |
| 247 | from Crypto.Signature import PKCS1_v1_5 |
| 248 | from binascii import b2a_hex |
| 249 | |
| 250 | if sign_algo not in ("MD5", "SHA1", "SHA256", "SHA384", "SHA512"): |
| 251 | raise ValueError("Unsupported Signing algorithm") |
| 252 | |
| 253 | |
| 254 | priv_key = RSA.importKey(pem_private, passphrase=pem_passphrase) |
| 255 | signer = PKCS1_v1_5.new(priv_key) |
| 256 | digest = getattr(__import__('Crypto.Hash', fromlist=[sign_algo]), sign_algo).new() |
| 257 | digest.update(message) |
| 258 | return b2a_hex(signer.sign(digest)) |
| 259 | |
| 260 | def format_time(value): |
| 261 | dt = datetime.datetime(1, 1, 1) + \ |
no test coverage detected