0

我下载了 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)
4

1 回答 1

0

我不知道它是否是内部的,或者编码文本是否是您传入的东西。这可能是一个 unicode 字符串被强制转换为“char const *”以外的东西的问题。在这种情况下,您可以对字符串进行编码,也可以使用常规的 ascii 字符串代替 unicode 字符串。

看到这个:https ://github.com/chokkan/simstring/issues/6

于 2012-09-07T08:13:10.330 回答