我下载了 64 位 Python 2.7 的试用版:chilkat-9.3.2-python-2.7-x86_64-linux.tar.gz。我发现了一个奇怪的问题:当我编写一种方法(如下所示的 decrypRSA() )将解码给定的 RSA 加密字符串时,它只有在我直接在 linux 的命令行中调用它时才有效。当在其他方法中调用它来响应 http 请求时,它肯定会抛出异常。我没有在网站上找到任何解决此问题的问题。
Here is the exception stack track:
File "/data/api_test.xxx.com/0/v0/share/auth/utils.py", line 301, in decrypRSA
return rsa.decryptStringENC(encodedText,False)
File "/usr/local/lib/python2.7/site-packages/chilkat.py", line 1319, in decryptStringENC
def decryptStringENC(self, *args): return _chilkat.CkRsa_decryptStringENC(self, *args)
TypeError: in method 'CkRsa_decryptStringENC', argument 2 of type 'char const *'
And here is the definition for decrypRSA() method:
@staticmethod
def decrypRSA(encodedText, publicKey):
print ('Utils.decrypRSA()-parameters: encodeText=%s, public key=%s' % (encodedText, publicKey,))
rsa = CkRsa()
success = rsa.UnlockComponent("30-day trial")
if (success != True):
logging.info("Utils.decrypRSA(): RSA component unlock failed")
return ''
# Import the public key into the RSA object:
success = rsa.ImportPublicKey(publicKey)
if (success != True):
logging.info("Utils.decrypRSA(): RSA failed to import public key: %s" % rsa.lastErrorText())
return ''
rsa.put_EncodingMode("base64")
rsa.put_LittleEndian(True)
return rsa.decryptStringENC(encodedText,False)