从摘要中获取单个unicode字符串::hm

2024-04-19 09:24:05 发布

您现在位置:Python中文网/ 问答频道 /正文

如何获得一个unicode字符串作为下面的签名(而不是字符向量(似乎包含unicode字符串片段)?你知道吗

例如

  library(digest)

  raw_key = 'QQrawkeyrawkeyrawkeyrawkey4='
  key = RCurl::base64Decode(raw_key)
  url_test = 'example_url'
  signature <- digest::hmac(key, url_test, algo = "sha1", raw = T)

返回字符向量

64 d9 cb 13 d3 f9 5c 0a 4c 1d 47 d2 d5 9d ab 24 25 3f f3 20

但我要它返回单个字符串 'd\xd9\xcb\x13\xd3\xf9\\nL\x1dG\xd2\xd5\x9d\xab$%?\xf3'

背景:

我试图让R代码与下面的python代码一样工作(我对python不是很有经验)。你知道吗

     raw_key = 'QQrawkeyrawkeyrawkeyrawkey4='
     key = base64.urlsafe_b64decode(raw_key)
     url_test = 'example_url'
     hmac.new(key, url_test.encode(), hashlib.sha1).digest()

另外一个上下文是,我需要使用字符串为使用高级帐户的googledistance matrix API调用创建签名。你知道吗


Tags: key字符串代码testurlrawexamplelibrary