GithubHelp home page GithubHelp logo

tadakoglu / netcore.encrypt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mylovecc/netcore.encrypt

0.0 2.0 0.0 123 KB

NETCore encrypt and decrpty tool,Include aes,des,rsa,md5,sha1,sha256,sha384,sha512

License: MIT License

C# 100.00%

netcore.encrypt's Introduction

NETCore.Encrypt 中文文档

NuGet NETCore CLR NetStandard 2.0.3 license

NETCore encrypt and decrpty tool,Include AES,RSA,MD5,SAH1,SAH256,SHA384,SHA512 and more

To install NETCore.Encrypt, run the following command in the Package Manager Console

Install-Package NETCore.Encrypt -Version 2.0.7

Easy to use with EncryptProvider

AES

Create AES Key

var aesKey = EncryptProvider.CreateAesKey();

var key = aesKey.Key;
var iv = aesKey.IV;

AES encrypt

  • AES encrypt without iv

    var srcString = "aes encrypt";
    var encrypted = EncryptProvider.AESEncrypt(srcString, key);
  • AES encrypt with iv

    var srcString = "aes encrypt";
    var encrypted = EncryptProvider.AESEncrypt(srcString, key, iv);
  • AES encrypt bytes at version 2.0.6

    var srcBytes = new byte[]{xxx};
    var encryptedBytes = EncryptProvider.AESEncrypt(srcBytes, key, iv);

ASE decrypt

  • AES decrypt without iv

    var encryptedStr = "xxxx";
    var decrypted = EncryptProvider.AESDecrypt(encryptedStr, key);
  • AES decrypt with iv

    var encryptedStr = "xxxx";
    var decrypted = EncryptProvider.AESDecrypt(encryptedStr, key, iv);
  • AES decrypt bytes at version 2.0.6

    var encryptedBytes =  new byte[]{xxx};
    var decryptedBytes = EncryptProvider.AESDecrypt(encryptedBytes, key, iv);

DES (version 2.0.2)

  • Create DES Key

    //des key length is 24 bit
    var desKey = EncryptProvider.CreateDesKey();
  • DES encrypt

    var srcString = "des encrypt";
    var encrypted = EncryptProvider.DESEncrypt(srcString, key);
  • DES encrypt bytes at version 2.0.6

    var srcBytes =  new byte[]{xxx};
    var decryptedBytes = EncryptProvider.DESEncrypt(srcBytes, key);
  • DES decrypt

    var encryptedStr = "xxxx";
    var decrypted = EncryptProvider.DESDecrypt(encryptedStr, key);
  • DES decrypt bytes at version 2.0.6

    var encryptedBytes =  new byte[]{xxx};
    var decryptedBytes = EncryptProvider.DESDecrypt(encryptedBytes, key);

RSA

  • Enum RsaSize

     public enum RsaSize
    {
        R2048=2048,
        R3072=3072,
        R4096=4096
    }
  • Create RSA Key with RsaSize(update at version 2.0.1)

    var rsaKey = EncryptProvider.CreateRsaKey();    //default is 2048
    
    // var rsaKey = EncryptProvider.CreateRsaKey(RsaSize.R3072);
    
    var publicKey = rsaKey.PublicKey;
    var privateKey = rsaKey.PrivateKey;
    var exponent = rsaKey.Exponent;
    var modulus = rsaKey.Modulus;
  • RSA encrypt

    var publicKey = rsaKey.PublicKey;
    var srcString = "rsa encrypt";
    
    
    var encrypted = EncryptProvider.RSAEncrypt(publicKey, srcString);
    
    // On mac/linux at version 2.0.5
    var encrypted = EncryptProvider.RSAEncrypt(publicKey, srcString, RSAEncryptionPadding.Pkcs1);
  • RSA decrypt

    var privateKey = rsaKey.PrivateKey;
    var encryptedStr = "xxxx";
    
    var decrypted = EncryptProvider.RSADecrypt(privateKey, encryptedStr);
    
    // On mac/linux at version 2.0.5
    var decrypted = EncryptProvider.RSADecrypt(privateKey, encryptedStr, RSAEncryptionPadding.Pkcs1);
  • RSA from string (add at version 2.0.1)

    var privateKey = rsaKey.PrivateKey;
    RSA rsa = EncryptProvider.RSAFromString(privateKey);

MD5

var srcString = "Md5 hash";
var hashed = EncryptProvider.Md5(srcString);
var srcString = "Md5 hash";
var hashed = EncryptProvider.Md5(srcString, MD5Length.L16);

SHA

  • SHA1

    var srcString = "sha hash";    
    var hashed = EncryptProvider.Sha1(srcString); 
  • SHA256

    var srcString = "sha hash";    
    var hashed = EncryptProvider.Sha256(srcString); 
  • SHA384

    var srcString = "sha hash";    
    var hashed = EncryptProvider.Sha384(srcString); 
  • SHA512

    var srcString = "sha hash";    
    var hashed = EncryptProvider.Sha512(srcString);

HMAC

  • HMAC-MD5

    var key="xxx";
    var srcString = "hmac md5 hash";     
    var hashed = EncryptProvider.HMACMD5(srcString,key);
  • HMAC-SHA1

    var key="xxx";
    var srcString = "hmac sha hash";    
    var hashed = EncryptProvider.HMACSHA1(srcString,key);
  • HMAC-SHA256

    var key="xxx";
    var srcString = "hmac sha hash";    
    var hashed = EncryptProvider.HMACSHA256(srcString,key);
  • HMAC-SHA384

    var key="xxx";
    var srcString = "hmac sha hash";    
    var hashed = EncryptProvider.HMACSHA384(srcString,key);
  • HMAC-SHA512

    var key="xxx";
    var srcString = "hmac sha hash";    
    var hashed = EncryptProvider.HMACSHA512(srcString,key);

Base64

  • Base64Encrypt

    var srcString = "base64 string";    
    var hashed = EncryptProvider.Base64Encrypt(srcString);   //default encoding is UTF-8
    var srcString = "base64 string";    
    var hashed = EncryptProvider.Base64Encrypt(srcString,Encoding.ASCII);  
  • Base64Decrypt

    var encryptedStr = "xxxxx";    
    var strValue = EncryptProvider.Base64Decrypt(encryptedStr);   //default encoding is UTF-8
    var encryptedStr = "xxxxx";    
    var strValue = EncryptProvider.Base64Decrypt(encryptedStr,Encoding.ASCII); 

Easy to use hash with EncryptExtensions

MD5 Extensions

  • String to MD5

var hashed="some string".MD5();

SHA Extensions

  • String to SHA1

var hashed="some string".SHA1();

Tips:SHA256,SHA384,SHA512 the same usage like SHA1

HMACSHA Extensions

  • String to HMACSHA1

  var key="xxx";
  var hashed="some string".HMACSHA1(key);

Tips:HMACSHA256,HMACSHA384,HMACSHA512 the same usage like HMACSHA1

LICENSE

MIT License

netcore.encrypt's People

Contributors

mylovecc avatar catcherwong avatar jacobpretorius avatar

Watchers

James Cloos avatar Tayfun Adakoğlu avatar

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.