Python ed25519 to curve25519

使用 PyNaCl 这个库:pip install PyNaCl

import nacl.bindings

# ed25519 to curve25519
curve25519_key = nacl.bindings.crypto_sign_ed25519_sk_to_curve25519(private_key)

# scalar multiplication: curve25519_key * public
pin_key = nacl.bindings.crypto_scalarmult(curve25519_key, pin_token_bytes)

Python 格式化数字之千分位

'{:,}'.format(value)  # For Python ≥2.7
f'{value:,}'          # For Python ≥3.6
import locale
locale.setlocale(locale.LC_ALL, '')  #  '' 空字符自动选择, 或者指定,例如 'en_US.UTF-8'

'{:n}'.format(value)  # For Python ≥2.7
f'{value:n}'          # For Python ≥3.6

参考文章

如何搜索本站文章

🔍搜索框快捷键:Ctrl + K

使用类 Unix 搜索命令语法。
例如搜索包含 helloworld 的文章:'hello 'world

语法详情:

  • 空格充当**逻辑与(AND)**操作符,
  • 竖线(|)字符充当**逻辑或(OR)**操作符。
    要搜索空白(转义空白)请使用双引号。举例:'"hello world",用于搜索包含“hello world” 的文章。
语法示例 匹配类型 说明
jscript 模糊匹配 Items that fuzzy match jscript
=scheme 精确匹配 Items that are scheme
'python 包含 Items that include python
!ruby 不包含 Items that do not include ruby
^java 以指定字符开头的 java 开头的内容
!^earlang 不以指定字符开头的 不以 earlang 开头的内容
.js$ 以某字符结尾的 .js 结尾的内容
!.go$ 不以某字符结尾的 不以 .go 结尾的内容

AWS API Gateway 请求时报错 no 'Access-Control-Allow-Origin' header

用浏览器请求 REST API,发现浏览器端总是报错:no ‘Access-Control-Allow-Origin’ header。但是 Postman 里请求 API 是正常的。

这是因为浏览器跨域请求 API,发现服务器不支持 CORS。

比如在本地测试的网页地址是:http://127.0.0.1:3000/,该页面的 JS 请求的 API 地址是:https://xxx.execute-api.xxx.amazonaws.com/