Giter VIP home page Giter VIP logo

stulzq / rsautil Goto Github PK

View Code? Open in Web Editor NEW
279.0 22.0 82.0 1.65 MB

.NET Core RSA algorithm using the help tool.It supports data encryption, decryption, signature and verification signature.It supports three key formats, namely: xml, pkcs1, pkcs8.It also supports key conversion for these three formats.Last also support pem formatting.

License: MIT License

C# 98.13% Shell 1.87%
dotnet-core rsa rsa-xml rsa-pkcs1 rsa-pkcs8 rsa-convert pem

rsautil's Introduction

RSAUtil 中文文档

Build Status

.NET Core RSA algorithm using the help tool.It supports data encryption, decryption, signature and verification signature.It supports three key formats, namely: xml, pkcs1, pkcs8.It also supports key conversion for these three formats.Last also support pem formatting.

Thanks for onovotny's bc-csharp

Latest version

Install

Install-Package XC.RSAUtil

The old package name is XC.Framework.Security.RSAUtil. Now renamed XC.RSAUtil and will continue to use.

Doc

Generate the key

Use class RsaKeyGenerator.The result returned is a list of two-element strings,Element 1 is the private key and element 2 is the public key.

Format: XML

var keyList = RsaKeyGenerator.XmlKey(2048);
var privateKey = keyList[0];
var publicKey = keyList[1];

Format: Pkcs1

var keyList = RsaKeyGenerator.Pkcs1Key(2048);
var privateKey = keyList[0];
var publicKey = keyList[1];

Format: Pkcs8

var keyList = RsaKeyGenerator.Pkcs8Key(2048);
var privateKey = keyList[0];
var publicKey = keyList[1];

RSA key conversion

Use class RsaKeyConvert.It supports key conversion for these three formats,namely: xml, pkcs1, pkcs8.

XML->Pkcs1:
  • Private Key : RsaKeyConvert.PrivateKeyXmlToPkcs1()
  • Public Key : RsaKeyConvert.PublicKeyXmlToPem()
XML->Pkcs8:
  • Private Key : RsaKeyConvert.PrivateKeyXmlToPkcs8()
  • Public Key : RsaKeyConvert.PublicKeyXmlToPem()
Pkcs1->XML:
  • Private Key : RsaKeyConvert.PrivateKeyPkcs1ToXml()
  • Public Key : RsaKeyConvert.PublicKeyPemToXml()
Pkcs1->Pkcs8:
  • Private Key : RsaKeyConvert.PrivateKeyPkcs1ToPkcs8()
  • Public Key : No conversion required
Pkcs8->XML:
  • Private Key : RsaKeyConvert.PrivateKeyPkcs8ToXml()
  • Public Key : RsaKeyConvert.PublicKeyPemToXml()
Pkcs8->Pkcs1:
  • Private Key : RsaKeyConvert.PrivateKeyPkcs8ToPkcs1()
  • Public Key : No conversion required

Encrypt, decrypt, sign, and verify signatures

XML, Pkcs1, Pkcs8 respectively corresponding categories: RsaXmlUtil, RsaPkcs1Util, RsaPkcs8Util.They inherit from the abstract class RSAUtilBase

  • Encrypt: RSAUtilBase.Encrypt()
  • Decrypt: RSAUtilBase.Decrypt()
  • Sign: RSAUtilBase.SignData()
  • Verify: RSAUtilBase.VerifyData()

PEM formatting

Use class RsaPemFormatHelper.

  • Format Pkcs1 format private key: RsaPemFormatHelper.Pkcs1PrivateKeyFormat()

  • Remove the Pkcs1 format private key format: RsaPemFormatHelper.Pkcs1PrivateKeyFormatRemove()

  • Format Pkcs8 format private key: RsaPemFormatHelper.Pkcs8PrivateKeyFormat()

  • Remove the Pkcs8 format private key format: RsaPemFormatHelper.Pkcs8PrivateKeyFormatRemove()

Reference component

bc-csharp - onovotny

Cases

dotnetrsa - DotnetRSA is a .NET Core Global Tool.Dotnet RSA Tool can help you generate xml pkcs1, pkcs8 three kinds of format keys, and supports three types of mutual conversion.

rsautil's People

Contributors

alexinea avatar daullmer avatar ren8179 avatar stulzq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rsautil's Issues

bigdata error

Error: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

var keyList = RsaKeyGenerator.Pkcs1Key(2048, false);
......

var bigDataRsa = new RsaPkcs1Util(Encoding.UTF8, PUBLIC_KEY, PRIVATE_LEY, 2048);
var text=bigDataRsa.EncryptBigData("12312312312", RSAEncryptionPadding.Pkcs1);
......
var bigDataRsa = new RsaPkcs1Util(Encoding.UTF8, PUBLIC_KEY, PRIVATE_LEY, 2048);
var result= string.Join("", bigDataRsa.DecryptBigData(data, RSAEncryptionPadding.Pkcs1));
......
  public const string PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA85hHtD6EsFDETuyWcNd/TPBh5ljTO831aagxC0eKSVokCJlh5Y0CIdXd7iI4pRnCO9sej2ZL4p3wKgQqRF0dAWu8wUuxcXyqlNsdSAl25JLHaRpaE/hwDO3weSiLPao8eTjqepV2q0eJX6nJ5QU6L5E9W7vUDMQ1nlEVbclKJl3SSNTuFGVqyk8RtjG35vJkmeV1P5TL3yOMxbGmJnEqfR/dVo/ikv7sTYWvVLOzPStkTYroYPZnLKjV6r55UuKDgxVPKx5MoJB7EzSIkKqbfic1f5vscNFASWo2tW2adUvUA89wWs2YRzY5bZHmA9Ufdl8tRxAK+gb5YYGSTYkTdwIDAQAB";
public const string PRIVATE_LEY = "MIIEowIBAAKCAQEA85hHtD6EsFDETuyWcNd/TPBh5ljTO831aagxC0eKSVokCJlh5Y0CIdXd7iI4pRnCO9sej2ZL4p3wKgQqRF0dAWu8wUuxcXyqlNsdSAl25JLHaRpaE/hwDO3weSiLPao8eTjqepV2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f9ou7SuWUPwKBgDfPZRz6GTgsFeiM8FmEl7e80tFy1k1fqxr7PmVHKaWJ+rQr+bN1z/uRw/T6mHXmc8qLskhKz9tX0Asl5anX9DHEPKOxt69r7Ixz/YURqf+SCtUg9FzWsESCMiWzV3vg9Fjw1eH8yzHhZSSJGptESrjDkY4Je3xiu7VaD8TttpvhAoGBAOJ/mxzyIfQuBNSFmrjLiCWdtwElEqwf2K/iimmIr04i5bGjMcMDejNlBUoSWTUmS+3HcIuUz8XetqzvCbRnG4Ozv/edrVA/oYYAQSKmjjo1DWqTBm0zWt59C5U12ZhTwsgVCjMrqiL5z5SlhR//0dQE7NPqTR8HgwSJrQZYmj3m";

my encryption result

HawPwqw9AKffjb1hedGoDT71JB0hfxgCCj35h+XMkoPpAjtn7Bdl3i0QOv7lulAoFa1cp6x8Jf5WhbvRsrDyDGW5Gile3Uwdzkj0Nhdyo6Fdh4Vxh8dgkLle6UIoixA3wvgNQME2tvZNhwBT7r9ZIZkdUP10kKnljTSU+lxeCFZ+XbTQZ7tbLXL6oNajCe/ecOT7/gve/+qtDYvn1TUVf8fN2RehtqfEwSwKdXaEqicFfQJOBt3iKjOrAsUeKu2fL3lkppkMNCM+3oB7h64Yx51UwOe6+l0s3EQ5HDw/nP04ZmES6W2Srg0JOY2NJy8k5UvzxxuaCp8V3bKOnYKIbg==

why i must input privatekey when decrypt. in fact , your code privatekey default value is null.
thank you.

加密长度问题

不知道有没有长度的解决方案?
我直接拿来跑不动..
提示 参数错误
测试发现是加密传过长了

Removing local BouncyCastle.Crypto and using NuGet package ?

I am not sure if you have a custom version of BouncyCastle for yourself in this project but if no, it would be good to use the original nuget package for easier update and fix ambiguous references while using BouncyCastle in my own project for other encryptions (AES, DES, ...)

有错误

TIM截图20190610160909
使用同一个pkcs8加密出来的数据解密居然报错了。。。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.