GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - MidLevel/MLAPI.Cryptography: Unity friendly library for networked cryptography.

BranchesTags
Open more actions menu

Latest commit

 

History

13 Commits
13 Commits

Folders and files

NameName
Last commit message
Last commit date
MLAPI.Cryptography.Examples
MLAPI.Cryptography.Examples
 
 
MLAPI.Cryptography
MLAPI.Cryptography
 
 
.gitignore
.gitignore
 
 
FUNDING.yml
FUNDING.yml
 
 
LICENCE
LICENCE
 
 
MLAPI.Cryptography.sln
MLAPI.Cryptography.sln
 
 
README.md
README.md
 
 

Repository files navigation

MLAPI.Cryptography

MLAPI.Cryptography is a Unity friendly crypto library to fill the missing features of Unity's Mono runtime framework.

Currently it offers a BigInt, ECDHE, ECDHE_RSA and EllipticCurve implementation. Note that MLAPI.Cryptography is NOT designed to be an extensive crypto library such as NaCL or replace the .NET Framework. It's simply there to fill the missing gaps in the Unity Engine. Behind the scenes, MLAPI.Cryptography will use as much of the avalible .NET surface as possible. An example of this is the ECDHE_RSA implementation which uses MLAPI.Cryptographys BigInt, EllipticCurve and DiffieHellman implementations while it uses .NET's RSA implementation.

ECDHE Usage

// Both create their instances
ECDiffieHellman serverDiffie = new ECDiffieHellman();
ECDiffieHellman clientDiffie = new ECDiffieHellman();

// Exchange publics

/* START TRANSMISSION */
byte[] serverPublic = serverDiffie.GetPublicKey();
byte[] clientPublic = clientDiffie.GetPublicKey();
/* END TRANSMISSION */

// Calculate shared
byte[] key1 = serverDiffie.GetSharedSecretRaw(clientPublic);
byte[] key2 = clientDiffie.GetSharedSecretRaw(serverPublic);

ECDHERSA Usage

// Key pairs
RSAParameters privateKey;
RSAParameters publicKey;

// Generate keys, you can use X509Certificate2 instead of raw RSA keys.
using (RSACryptoServiceProvider rsaGen = new RSACryptoServiceProvider(2048))
{
    privateKey = rsaGen.ExportParameters(true);
    publicKey = rsaGen.ExportParameters(false);
}

using (RSACryptoServiceProvider serverRSA = new RSACryptoServiceProvider())
using (RSACryptoServiceProvider clientRSA = new RSACryptoServiceProvider())
{
    serverRSA.ImportParameters(privateKey);
    clientRSA.ImportParameters(publicKey);

    // Both create their instances, constructor can take certificate instead or RSA key.
    ECDiffieHellmanRSA serverDiffie = new ECDiffieHellmanRSA(serverRSA);
    ECDiffieHellmanRSA clientDiffie = new ECDiffieHellmanRSA(clientRSA);

    // Exchange publics

    /* START TRANSMISSION */
    byte[] serverPublic = serverDiffie.GetSecurePublicPart();
    byte[] clientPublic = clientDiffie.GetSecurePublicPart();
    /* END TRANSMISSION */

    // Calculate shared
    byte[] key1 = serverDiffie.GetVerifiedSharedPart(clientPublic);
    byte[] key2 = clientDiffie.GetVerifiedSharedPart(serverPublic);
}

Timing Side Channel Attack Prevention

byte[] array1 = new byte[120];
byte[] array2 = new byte[120];
array[50] = 67;

// This comparison will take constant time, no matter where the diff is (if any).
bool equal = ComparisonUtils.ConstTimeArrayEqual(array1, array2);

About

Unity friendly library for networked cryptography.

Resources

Readme
MIT license
Activity
Custom properties

Stars

14 stars

Watchers

1 watching

Forks

4 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.