用苹果公钥创建一个x.509标准的公钥怎么做?
要创建一个X.509标准的公钥, 首先需要获取苹果公钥. 可以从苹果开发者网站上获取苹果公钥, 然后使用OpenSSL工具将其转换为X.509标准的公钥. 具体步骤如下:
- 从苹果开发者网站上下载苹果公钥, 并将其保存为.pem格式的文件.
- 使用OpenSSL工具将.pem格式的文件转换为X.509标准的公钥, 命令如下:
openssl x509 -in apple.pem -out apple.cer -outform DER
- 将转换后的X.509标准的公钥保存为.cer格式的文件.
Python创建x.509标准密钥代码示例
以下是使用Python创建X.509标准密钥的示例代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa # Generate a private key private_key = rsa.generate_private_key( public_exponent=65537, key_size=2048, backend=default_backend() ) # Serialize the private key pem = private_key.private_bytes( encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.PKCS8, encryption_algorithm=serialization.NoEncryption() ) # Write the private key to a file with open('private_key.pem', 'wb') as f: f.write(pem) # Generate a public key public_key = private_key.public_key() # Serialize the public key pem = public_key.public_bytes( encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo ) # Write the public key to a file with open('public_key.pem', 'wb') as f: f.write(pem) |
from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa # Generate a private key private_key = rsa.generate_private_key( public_exponent=65537, key_size=2048, backend=default_backend() ) # Serialize the private key pem = private_key.private_bytes( encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.PKCS8, encryption_algorithm=serialization.NoEncryption() ) # Write the private key to a file with open('private_key.pem', 'wb') as f: f.write(pem) # Generate a public key public_key = private_key.public_key() # Serialize the public key pem = public_key.public_bytes( encoding=serialization.Encoding.PEM, format=serialization.PublicFormat.SubjectPublicKeyInfo ) # Write the public key to a file with open('public_key.pem', 'wb') as f: f.write(pem)
强烈推荐
- 英国代购-畅购英伦
- TopCashBack 返现 (英国购物必备, 积少成多, 我2年来一共得了3000多英镑)
- Quidco 返现 (也是很不错的英国返现网站, 返现率高)
- 注册就送10美元, 免费使用2个月的 DigitalOcean 云主机(性价比超高, 每月只需5美元)
- 注册就送10美元, 免费使用4个月的 Vultr 云主机(性价比超高, 每月只需2.5美元)
- 注册就送10美元, 免费使用2个月的 阿里 云主机(性价比超高, 每月只需4.5美元)
- 注册就送20美元, 免费使用4个月的 Linode 云主机(性价比超高, 每月只需5美元) (折扣码: PodCastInit2022)
- PlusNet 英国光纤(超快, 超划算! 用户名 doctorlai)
- 刷了美国运通信用卡一年得到的积分 换了 485英镑
- 注册就送50英镑 – 英国最便宜最划算的电气提供商
- 能把比特币莱特币变现的银行卡! 不需要手续费就可以把虚拟货币法币兑换
微信公众号: 小赖子的英国生活和资讯 JustYYUK