参考:
def openssl_private_encrypt(key, data, backend): """Encrypt data with RSA private key. This is a rewrite of the function from PHP, using cryptography FFI bindings to the OpenSSL library. Private key encryption is non-standard operation and Python packages either don't offer it at all, or it's incompatible with the PHP version. The backend argument MUST be the OpenSSL cryptography backend. """ length = backend._lib.EVP_PKEY_size(key._evp_pkey) buffer = backend._ffi.new('unsigned char[]', length) result = backend._lib.RSA_private_encrypt( len(data), data, buffer, backend._lib.EVP_PKEY_get1_RSA(key._evp_pkey), backend._lib.RSA_PKCS1_PADDING) backend.openssl_assert(result == length) return backend._ffi.buffer(buffer)[:]from cryptography.hazmat.backends.openssl.backend import backendfrom cryptography.hazmat.primitives.serialization import load_pem_private_keyprivkey = load_pem_private_key(self.pri_key_str, None, backend)tmp = openssl_private_encrypt(privkey, md5Str, backend)