rsa.js 775 Bytes
import cryptico from 'cryptico';

class Rsa {
    constructor() {
        this.mattsRSAkey = cryptico.generateRSAKey('d7b7ac4b491fd2b1b9e27bc2ca9bf5d0', 1024);
        this.mattsPublicKeyString = cryptico.publicKeyString(this.mattsRSAkey);
    }
    encrypt(plainText) {
        if (typeof plainText === 'object') {
            plainText = encodeURIComponent(JSON.stringify(plainText));
        }
        return cryptico.encrypt(plainText, this.mattsPublicKeyString).cipher;
    }
    decrypt(cipherText, Type) {
        let plainText = cryptico.decrypt(cipherText, this.mattsRSAkey).plaintext;

        if (Type && Type.name === 'Object') {
            return JSON.parse(decodeURIComponent(plainText));
        }
        return plainText;
    }
}

export default new Rsa();