<commit_before># OpenCrypto
[![Build Status](https://travis-ci.org/safebash/opencrypto.svg?branch=master)](https://travis-ci.org/safebash/OpenCrypto)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://raw.githubusercontent.com/safebash/OpenCrypto/master/LICENSE.md)

OpenCrypto is a lightweight JavaScript library built on top of WebCryptography API. The purpose of this library is to make it easier for a developer to implement cryptography in the browser with less code and without having to deal with ASN.1, PEM or other formats manually.

## Code Usage
### Load OpenCrypto into your web app
```javascript
<script type="text/javascript" src="OpenCrypto.min.js"></script>
```
### Examples
```javascript
// Initialize new OpenCrypto instance
const crypto = new OpenCrypto()

// Asymmetric Encryption (RSA)
// Generate asymmetric key pair
crypto.getKeyPair().then(function (keyPair) {
  console.log(keyPair.publicKey)
  console.log(keyPair.privateKey)
})

// Convert CryptoKey of type public to PEM
crypto.cryptoPublicToPem(keyPair.publicKey).then(function (publicPem) {
  console.log(publicPem)
})

// Convert CryptoKey of type private to PEM
crypto.cryptoPrivateToPem(keyPair.privateKey).then(function (privatePem) {
  console.log(privatePem)
})

// Convert PEM public key to CryptoKey
crypto.pemPublicToCrypto(publicPem).then(function (cryptoPublic) {
  console.log(cryptoPublic)
})

// Convert PEM private key to CryptoKey
crypto.pemPrivateToCrypto(privatePem).then(function (cryptoPrivate) {
  console.log(cryptoPrivate)
})

// Encrypt CryptoKey of type private into PEM Encrypted Private Key
crypto.encryptPrivateKey(cryptoPrivate, 'securepassphrase').then(function (encryptedPrivateKey) {
  // This PEM Encrypted Private Key is fully compatiable with OpenSSL
  console.log(encryptedPrivateKey)
})

// Decrypt PEM Encrypted Private Key
crypto.decryptPrivateKey(encryptedPrivateKey, 'securepassphrase').then(function (decryptedPrivateKey) {
  console.log(decryptedPrivateKey)
})

// Encrypt data using public key
crypto.encryptPublic(publicKey, data).then(function (encryptedDataAsymmetric) {
  console.log(encryptedDataAsymmetric)
})

// Decrypt data using private key
crypto.decryptPrivate(privateKey, encryptedDataAsymmetric).then(function (decryptedDataAsymmetric) {
  console.log(decryptedDataAsymmetric)
})

// Encrypt session key
crypto.encryptKey(publicKey, sessionKey).then(function (encryptedSessionKey) {
  console.log(encryptedSessionKey)
})

// Decrypt session key
crypto.sessionKey(privateKey, encryptedSessionKey).then(function (decryptedSessionKey) {
  console.log(decryptedSessionKey)
})

// Symmetric Encryption (AES)
// Generate new symmetric / session Key
crypto.getSharedKey().then(function (sharedKey) {
  console.log(sharedKey)
})

// Encrypt data using shared key
crypto.encrypt(sharedKey, data).then(function (encryptedData) {<commit_msg>README.md additional edit<commit_after># OpenCrypto
[![Build Status](https://travis-ci.org/safebash/opencrypto.svg?branch=master)](https://travis-ci.org/safebash/opencrypto)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://raw.githubusercontent.com/safebash/opencrypto/master/LICENSE.md)

OpenCrypto is a lightweight JavaScript library built on top of WebCryptography API. The purpose of this library is to make it easier for a developer to implement cryptography in the browser with less code and without having to deal with ASN.1, PEM or other formats manually.

## Code Usage
### Load OpenCrypto into your web app
```javascript
<script type="text/javascript" src="OpenCrypto.min.js"></script>
```
### Examples
```javascript
// Initialize new OpenCrypto instance
const crypto = new OpenCrypto()

// Asymmetric Encryption (RSA)
// Generate asymmetric key pair
crypto.getKeyPair().then(function (keyPair) {
  console.log(keyPair.publicKey)
  console.log(keyPair.privateKey)
})

// Convert CryptoKey of type public to PEM
crypto.cryptoPublicToPem(keyPair.publicKey).then(function (publicPem) {
  console.log(publicPem)
})

// Convert CryptoKey of type private to PEM
crypto.cryptoPrivateToPem(keyPair.privateKey).then(function (privatePem) {
  console.log(privatePem)
})

// Convert PEM public key to CryptoKey
crypto.pemPublicToCrypto(publicPem).then(function (cryptoPublic) {
  console.log(cryptoPublic)
})

// Convert PEM private key to CryptoKey
crypto.pemPrivateToCrypto(privatePem).then(function (cryptoPrivate) {
  console.log(cryptoPrivate)
})

// Encrypt CryptoKey of type private into PEM Encrypted Private Key
crypto.encryptPrivateKey(cryptoPrivate, 'securepassphrase').then(function (encryptedPrivateKey) {
  // This PEM Encrypted Private Key is fully compatiable with OpenSSL
  console.log(encryptedPrivateKey)
})

// Decrypt PEM Encrypted Private Key
crypto.decryptPrivateKey(encryptedPrivateKey, 'securepassphrase').then(function (decryptedPrivateKey) {
  console.log(decryptedPrivateKey)
})

// Encrypt data using public key
crypto.encryptPublic(publicKey, data).then(function (encryptedDataAsymmetric) {
  console.log(encryptedDataAsymmetric)
})

// Decrypt data using private key
crypto.decryptPrivate(privateKey, encryptedDataAsymmetric).then(function (decryptedDataAsymmetric) {
  console.log(decryptedDataAsymmetric)
})

// Encrypt shared key
crypto.encryptKey(publicKey, sharedKey).then(function (encryptedSharedKey) {
  console.log(encryptedSharedKey)
})

// Decrypt shared key
crypto.decryptKey(privateKey, encryptedSharedKey).then(function (decryptedSharedKey) {
  console.log(decryptedSharedKey)
})

// Symmetric Encryption (AES)
// Generate new symmetric / shared Key
crypto.getSharedKey().then(function (sharedKey) {
  console.log(sharedKey)
})

// Encrypt data using shared key
crypto.encrypt(sharedKey, data).then(function (encryptedData) {
{'fraction_non_alphanumeric': 0.11018854869399758, 'fraction_numerical': 0.0003459609064175748, 'mean_word_length': 5.983091787439614, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5946112', 'n_tokens_mistral': 1765, 'n_tokens_neox': 1720, 'n_words': 414}