ColdFusion:整数“0”不转换为 ASCII 字符

发布于 2024-09-29 16:06:45 字数 660 浏览 3 评论 0原文

我有一个字符串(由用户 ID 和日期/时间戳组成),然后使用 ColdFusion 的 Encrypt(inputString, myKey, "Blowfish/ECB/PKCS5Padding", "Hex") 对其进行加密。

为了与 3d 方交互,我必须执行以下操作:

  1. 将结果字符串中的每个字符对转换为十六进制值。
  2. 然后十六进制值表示为整数。
  3. 然后将结果整数作为 ASCII 字符输出。
  4. 所有 ASCII 字符组合起来形成一个字节串。
  5. 然后将字节串转换为 Base64。
  6. Base64 经过 URL 编码并最终发送出去(唷!)

除了原始 cfEncrypted 字符串包含“00”之外,一切都无缝运行。

十六进制值 00 转换为整数(通过函数 InputBaseN)0,然后它拒绝正确转换为 ASCII 字符!

生成的字节串(以及 URL 字符串)被搞乱,3d 方无法破译它。

值得一提的是,我声明:位于页面顶部。

有没有办法正确地将 00 输出为 ASCII?我可以避免在原始加密字符串中出现“00”吗?任何帮助将不胜感激:)

I have a string (comprised of a userID and a date/time stamp), which I then encrypt using ColdFusion's Encrypt(inputString, myKey, "Blowfish/ECB/PKCS5Padding", "Hex").

In order to interface with a 3d party I have to then perform the following:

  1. Convert each character pair within the resultant string into a HEX value.
  2. HEX values are then represented as integers.
  3. Resultant integers are then output as ASCII characters.
  4. All the ASCII characters combine to form a Bytestring.
  5. Bytestring is then converted to Base64.
  6. Base64 is URL encoded and finally sent off (phew!)

It all works seamlessly, APART FROM when the original cfEncrypted string contains a "00".

The HEX value 00 translates as the integer (via function InputBaseN) 0 which then refuses to translate correctly into an ASCII character!

The resultant Bytestring (and therefore url string) is messed up and the 3d party is unable to decipher it.

It's worth mentioning that I do declare: <cfcontent type="text/html; charset=iso-8859-1"> at the top of the page.

Is there any way to correctly output 00 as ASCII? Could I avoid having "00" within the original encrypted string? Any help would be greatly appreciated :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一向肩并 2024-10-06 16:06:45

我非常确定 ColdFusion(以及下面的 Java)使用以 null 结尾的字符串类型。这意味着每个字符串包含一个且仅一个 asc(0) 字符,即字符串终止符。如果您尝试将 asc(0) 插入字符串,CF 会出错,因为您尝试创建格式错误的字符串元素。

我不确定最终的解决方案是什么。我会尝试使用 toBinary() 和 toString(),并与您的第三方供应商讨论发送原始十六进制值或类似值等解决方法。

I'm pretty sure ColdFusion (and the Java underneath) use a null-terminated string type. This means that every string contains one and only one asc(0) char, which is the string terminator. If you try to insert an asc(0) into a string, CF is erroring because you are trying to create a malformed string element.

I'm not sure what the end solution is. I would play around with toBinary() and toString(), and talk to your 3rd party vendor about workarounds like sending the raw hex values or similar.

遗弃M 2024-10-06 16:06:45

实际上有一个非常简单的解决方案。处理您的请求的信用卡公司需要您将其转换为十六进制小写字母。唯一处理的字符是 :,-,0-9 执行 if else 并将它们手动转换为字符串。

Actually there is a very easy solution. The credit card company who is processing your request needs you to convert it to lower case letters of hex. The only characters processed are :,-,0-9 do a if else and convert them manually into a string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文