您现在的位置: 首页 > 网站导航收录 > 百科知识百科知识
(nqdmq)-年级的妈妈4完整
公钥,数据,格式(nqdmq)-年级的妈妈4完整
发布时间:2020-12-06加入收藏来源:互联网点击:
例:PKCS#8 PEM 私钥
-----BEGIN PRIVATE KEY-----MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDXuqAQz+MyeKuC335rPshsHUFxLpZcBj97EiHq9qhvxMhLsMoa3YFvKlwktBoQWzZzgETls1N0H5E/yhV+pljN4TIubfsOQ68TUfJkr9b+S1/25KwOwUmMndqaFb/vcYj1QtWTl65OXOWLl3oKl7j2kwjmwtW8Smm97cEw15ijmRALP3qGvYyzL/YRIOHv+PmDpoMG0dedZRNzu7hdhkU/UrlaRLvDLHyUJPkM+4SJHVUa2epYFMB7OX/b4ZQR0unxIBea2HAo8byGqctOB41cXa6+t8dvRj2DhCXhMHGXKNU8DL9aALLmCbl2UTsJQyvNQ3FaT7TzQYswgOevjFttAgMBAAECggEBALltxOAukM91QZdAm917HbMwgmvS65M2G6Kht13LnoRT1Qaac14cP4FaG9HArRaaEHe/LXlzZqxN5f+6qDcwrOxqQUP/bOiZ7QbiTUOWkWoLR/VkITCdm6aumJQRVeVu5ZZLWGGA42agGv6duV0ZhPcM833GwwkRvUpv7rsY1i7nccUObhkv3ql8XjnCcz1rSSkf6W40+dp0pW2mCH6NPeT8kdtBH7mA/ZSK7ZMQbMGgLNdCx069o91POKP/nZ9V9Ex2Bviic2TqpilC6Z/9EryxA0HszknUMX7Lnuhr7Fsbn8wkvYLplebolTOrCy/athEZkGdwCrgdGFk7by/XsdECgYEA9BX0vnhr1d1A9rxzYYt/Xt3DqqtnQ8ETe4CldI3/XIJ3CcMI4f52dAk+Jl9V4vHu4HRKODWjJ67FDExQBu+FWUjk01rFSMmbsVJRenRyuGL4X5XTRwMCtcIcxfvYgttLVVpqCsDK2CredAxcu+RZ5eI0/Y4gc+BKzDIbSy1LQ2sCgYEA4kJUQ4BlIQHD2CEj49ORL/WzWk01Wi9A2ilQcVf/xbLeBJd04SemftHLF4ulKM6VZ4KyrTzewwM6rEw31fWo7dgxShwTdnMIHn3esTdZYK6O6zQ8PuEi/q4hTx4QYXDq63pKoDRTrkQAVZdTe0ujyczPXjdAKwYFobd3sk606ocCgYA7tpdedZVkB7HZ6vaLOZZafgRdX3tu3vBGOY3AuvBrEFvQ3o7wwtD1yEEVICOh1rAq5yg1IiIdFiuMu6qkV7qWwjeA4Wb8TJ4zPkFCpPRf2Y6Ly9qZN8pU7v0dDmTEdqOyaOEialH1ml87or6ZFN9NVw7BrSCRWKDT3bpBpP4RqwKBgQC/i5u+kaILsWzVOikiJOgTDBTMa/Sw5rQmfTdm3TLhca3XgUknm+OuFXmz8zrdMxb0zIbrdk64FbHET7otXo2m3ZHMxbwMWRIUjkbLDKqT2PORV2VxbjOsHEqCqlb/xxJ6S8uFmQcGzvbhfvzjsoN0wfkEMA4Y3j5CTAn/X/Z1XQKBgGG4qDagG1unSkpNfHfuqwjEjAkSR/pla4vJIaEaA94/gJ21upZfwjUUdRXJbk6W03OfSOlmy2zIeCguV+H/UkMOcmBqVX/tbCQy7weCQwwHU4Dluy7xJIzrgYRXIuV+3zk2D63+LAK84+ksbL61zCnaG86YfYxcClOZ/revxrnd-----END PRIVATE KEY-----四. .NET Core 3.0 RSA 新增功能.NET Core 3.0 官方增加了对 PKCS#1和 PKCS#8(密码) Key 导入和导出支持,PKCS# 1为默认格式。
方法名 说明 ExportRSAPrivateKey 导出 PKCS# 1 私钥 ExportRSAPublicKey 导出 PKCS# 1 公钥 ExportPkcs8PrivateKey 导出 PKCS# 8 私钥 ExportEncryptedPkcs8PrivateKey 导出 PKCS# 8 加密私钥 ImportRSAPrivateKey 导入 PKCS# 1 私钥 ImportRSAPublicKey 导入 PKCS# 1 公钥 ImportPkcs8PrivateKey 导入 PKCS# 8 私钥 ImportEncryptedPkcs8PrivateKey 导入 PKCS# 8 加密私钥
以 PKCS#1 格式为例,用法如下:
var rsa = RSA.Create();//导出Console.WriteLine("RSA PKCS#1 私钥:");Console.WriteLine(Convert.ToBase64String(rsa.ExportRSAPrivateKey()));Console.WriteLine("RSA PKCS#1 公钥:");Console.WriteLine(Convert.ToBase64String(rsa.ExportRSAPublicKey()));//导入rsa.ImportRSAPrivateKey(Convert.FromBase64String("MIIEogIBAAKCAQEArTLJkbnYqeNXjy1iznnEi8bZjVbP4NabvftKFMdYeCCHfeHXZEvaJFbWcybmWwfj4ZjHH+/hh1RRQVMNgQUD8uXYmdjn7bUAfeyT9ujSulEFzwM2Udm6XtnI5/K2WH9ZHEPqUqNgv0EEthV6Yz+SQYFSYO2xd+TzLMvnW/iCmgb9gQfl85L+cKVvQy2NOod3i+gbTwPM8im1fP43vqVUUE5OD+Hz1Hiwai/RJDC67ZhoSdv1Vor8t9uyg+03fa8gfPj52gFRyHh3y8d/bb1LrJwbXV3cBCLD9aw9bnW3rFRwpP+JuH9VKSpoRA3gwD3vhoz7Y8BBOsC6PSrusAm/lQIDAQABAoIBAH+yBTli+2JuUn0mqkWvM4EW0AlMKyILOHJ+1mSxgQG4gg0GuKai4ieOurfVw1r0W0hWOuHKG86KFQqDsF4ik4G/gs4TRRRWMhGlnoYZrFxgJlc1eBQq4iTSjzSsF1LyOYIEdLwO5uK7jjytYznPgga30UPTm9fYvo2VnHOLqsbiD98ljQmUa53b13wqsGBRaqLgY8cAt5maI/IUytQNKORw/OwLVkYYOuLCI6NCnUgLhvn/aQpvdcIU06xsZw+sEsSsax3idILv+4VrmlSg/8Bhi7m+2JW/ati3QeQ2TUTRhAs7XxHeTSNWnlQE/pCnlBYSWZZCOSferPh8cJwZobUCgYEAzJZaIBVRAcOhUwOd5zE57aLuT8Qxc9zWSw8iAtITc/R6QE1x8qqSHmUudhz6/yCk07x1AatwtVisWixBFmbeKqMBsEVMWgSNu/+J8G2Hndr/588ApHwNibLPkbyqS9AGg//JP69k2N3L8ykpveYupD/riE6ppTQaO7UFCzFjlvMCgYEA2LkaHln4yCS64hc7G93WkyzH77B0+H3VK05emWzOP7H7U6msN02LNFEns4f8F6qi9WjsKumnqdm3ghXGH+QvygQfRKbrN/B7bEKgWUV1rv+NzO9q25sijJk99lJGE1wuV8/T9bGHYLg3A8JInKhR+OhoEpsKsRn2geJ6lCGbgVcCgYBHO/angySQi7BJOlIppI85+egmZ/acFAGdYuiBuOnDDxXd+9k4GEIGSU6zG4YdfR1HCDBpY2s8CWMBhrUm+qxShi1ZVdeu5DUBh4lc6JY21YETEpVzsCn6jwMNCHb3LLiID3DgNs7TX+7afLOnBlWpJQR6koEpH4oezfmymwDFFwKBgGNdevwvhEE/le/TduZv79HK1mCvJvJHv1T7uaPenzHVCMZzJOK2SvzRuMI3tv2i3tRmJuIF/zmA+QJLuWsl1ENrYGq5nV8og24/ngVQM4To5rrviq7lkhGksSQe1MJLoXPhde1QWCGgVJkEmwY4plzZMd5V97D7lmo2zLzeK85BAoGAIeo1WXPc3JFb/wOAB8BvdOzyQHDZFTSawTnws3sWCNZvicWJozNfq8m4kFoG3aITUeimlb6CPqZaJabjLF/99gReDJDixAIJoU1dXY07aSrzMS6hK1lvl6eY5B5zW+wCkIpfyCQSTcVB6zQAU9MOCaokKu2zleBMVQqKWfWfz54="), out _); rsa.ImportRSAPublicKey(Convert.FromBase64String("MIIBCgKCAQEArTLJkbnYqeNXjy1iznnEi8bZjVbP4NabvftKFMdYeCCHfeHXZEvaJFbWcybmWwfj4ZjHH+/hh1RRQVMNgQUD8uXYmdjn7bUAfeyT9ujSulEFzwM2Udm6XtnI5/K2WH9ZHEPqUqNgv0EEthV6Yz+SQYFSYO2xd+TzLMvnW/iCmgb9gQfl85L+cKVvQy2NOod3i+gbTwPM8im1fP43vqVUUE5OD+Hz1Hiwai/RJDC67ZhoSdv1Vor8t9uyg+03fa8gfPj52gFRyHh3y8d/bb1LrJwbXV3cBCLD9aw9bnW3rFRwpP+JuH9VKSpoRA3gwD3vhoz7Y8BBOsC6PSrusAm/lQIDAQAB"), out _);输出:
使用是非常简单的,如果使用PKCS#8,更改一下上面示例代码的方法名就行了。
使用这些API需要的项目使用的目标框架满足:
平台名称 支持版本号 .NET Core =3.0 .NET Standard =2.1
五. RSAExtensions 介绍从上面可以看出,.NET Core 已经原生支持了PKCS#1和PKCS#8 ,这对于和其他语言对接是十分方便的,但是美中不足的是没有对 PEM 支持,以及对 XML 格式的支持。
RSAExtensions 项目就是为了弥补上面这个缺点且支持RSA大数据加密,基于 RSA 对象来添加的扩展方法,使用同样也是非常方便的。
开源地址: https://github.com/stulzq/RSAExtensions (希望来个Star支持一下)
Nuget: https://www.nuget.org/packages/RSAExtensions
RSAExtensions 功能如下:
提供以前Framework有的XML格式的密钥导入和导出提供对PKCS#1、PKCS#8 PEM格式导入和导出支持提供对PKCS#1、PKCS#8、XML格式的统一导入和导出提供对大数据分段加密的支持增加的API:
方法名 说明 ExportPrivateKey 统一导出私钥,支持 PKCS#1、PKCS#8、XML以及PEM格式化 ExportPublicKey 统一导出公钥,支持 PKCS#1、PKCS#8、XML以及PEM格式化 ImportPrivateKey 统一导入私钥,支持 PKCS#1、PKCS#8、XML以及PEM ImportPublicKey 统一导入公钥,支持 PKCS#1、PKCS#8、XML以及PEM ImportXmlPrivateKey 导入XML私钥 ImportXmlPublicKey 导入XML公钥 ExportXmlPrivateKey 导出XML私钥 ExportXmlPublicKey 导出XML公钥 EncryptBigData 大数据分段加密 DecryptBigData 大数据分段解密
六. RSAExtensions 使用using System.Security.Cryptography;var rsa=RSA.Create();导出PKCS#1 导出rsa.ExportPrivateKey(RSAKeyType.Pkcs1); //私钥rsa.ExportPublicKey(RSAKeyType.Pkcs1); // 公钥私钥输出:
MIIEpAIBAAKCAQEAv4pVuabfkk1NxEpIz4GYMpG69hyJDXAFJAIuUP3qCIhq081KRwrWW+0qQZp6MMTHHA/O+rHHTR6vfGBOo6yxcs9c4QCbnt/RhQ+bOmLizTJURiFrbgFU9q8dlpJ8OaoSBE3M2dY6wMhck+vEGSr1w7Fm+wH+IPPyKfNynPDYs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/CImGtI7QDc7MO/cLFOqW44xSRuRBa3qT/mJkJbf5KR57lkJkOwaN4diC8QzquN1aGIZD0Z/Lv0JUiaqfhuOho+VTdAPs2awsFN+T9uAzncdd1o7raY+3VdIqYxDIblFzbD8Squm2iy3iaENXAmyLxSH1pPsCgYAXZincMY50iTmF9qYaS9xs44d3riKRQpty97W+igW5MqFMmmajfy8QShVliG1cU10Hsvz0hAZ6SK5gl+Zp6CHrveuEr69+aee6Xjp3hiJKCEiId9ahCpr8EBPWYTi22azBzgGiXseqMEI2UR9SS6K7OZ2TRNwWOERuBsabERZQhQ==PKCS#1 PEM 导出rsa.ExportPrivateKey(RSAKeyType.Pkcs1,true);//私钥rsa.ExportPublicKey(RSAKeyType.Pkcs1,true);//公钥下一篇:返回列表
相关链接 |
||
网友回复(共有 0 条回复) |