我正在尝试将此Python代码转换为C#(理想情况下是.NET核心)。 Source
我的目标是将QR输入字符串转换为另一个包含json数据的字符串。请参阅提供的链接
#! /usr/bin/env python3
import json
import sys
import zlib
import base45
import cbor2
from cose.messages import CoseMessage
payload = sys.argv[1][4:]
print("decoding payload: "+ payload)
# decode Base45 (remove HC1: prefix)
decoded = base45.b45decode(payload)
# decompress using zlib
decompressed = zlib.decompress(decoded)
# decode COSE message (no signature verification done)
cose = CoseMessage.decode(decompressed)
# decode the CBOR encoded payload and print as json
print(json.dumps(cbor2.loads(cose.payload), indent=2))
我找不到任何适用于Zlib的NuGet软件包,该软件包可以正常工作。所以我在base45解码后被卡住了。谢谢你的提示
using System.Text; //Rystem.Text.Base45 NuGet
var removedHeader = testQrData.Substring(4);
var decoded = removedHeader.FromBase45();
byte[] rawBytes = Encoding.ASCII.GetBytes(decoded);
这个link可能有助于进一步调查
我过去曾使用ZXing库解码和创建二维码:
https://github.com/micjahn/ZXing.Net
你也可以试试:https://github.com/codebude/QRCoder
来自github页面的快速ZXing示例:
此示例读取二维码图像。
我不确定你的输入是什么,但我会假设它也是一个二进制格式的图像,所以你可能需要四处玩才能让它工作
我从NuGet添加了“Zlib.Portable”,并使用了“ZlibStream.UncompressString”
我被困在下一步“CoseMessage.decode”:/
相关问题 更多 >
编程相关推荐