Git Product home page Git Product logo

stringcrypt's Introduction

StringCrypt

Simple (long) String encryption and signing for Android/Java using public keys

Allows to encrypt long Strings with RSA public key algorithm. RSA cipher is limited to a specific length in JAVA/Android. The String is encryped by symmetric DESede algorithm and only the symmetric session key is encrypted by RSA. The encrypted message and the symmetric key are packaged and can be exported as base64 encoded string or byte array.

The recipient can then decrypt the symmetric key with his private key and use the symmetric key to decrypt the message.

Signing is using a sha1 footprint of the message and signs it with the private key. The receiving party can use the senders public key to verify the validity of the signature.

Usage

Encrypting and decrypting Strings

// Init object
StringCrypt crypt = new StringCrypt();

// generate key pair for demonstration (or each party reads either from storage)
KeyPair kp = StringKeyTools.createKeyPair();
Key privateKey = kp.getPrivate();
Key publicKey = kp.getPublic();

// encrypt String message to CryptPackage and/or encode package as String
CryptPackage cryptPackage = crypt.encrypt(message, publicKey);
String packageString = cryptPackage.toString();

// ~~~ Do something with packageString, eg transmit over network

// Receiving party decrypt package from String
CryptPackage newPackage = new CryptPackage(packageString);
String decryptedString = crypt.decrypt(newPackage, privateKey);

Signing Strings

// Init object
StringSign sign = new StringSign();

// generate key pair for demonstration (or each party reads either from storage)
KeyPair kp = StringKeyTools.createKeyPair();
Key privateKey = kp.getPrivate();
Key publicKey = kp.getPublic();

// sign String with private key and return signature as String
String signature = sign.sign(message, privateKey);

// ~~~ Do something with signature string, eg transmit over network

// Receiving party can verify String with signature and public key of sender
Boolean verified = sign.verify(message, signature, publicKey);

Credits

Some elements are inspired from https://github.com/william-ferguson-au/asymmetric-crypto but I chose to simplify it even down to only two classes

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.