<commit_before># go-crypto [![Build Status](https://travis-ci.org/phylake/go-crypto.svg?branch=master)](https://travis-ci.org/phylake/go-crypto)

Go utilities for common tasks asked about around the internet

## Examples

### Encrypt a large file with a public key

```golang
package main

import (
    "crypto/rand"
    "crypto/rsa"
    "fmt"
    "github.com/phylake/go-crypto/pki"
)

func main() {
    rsaKey, err := rsa.GenerateKey(rand.Reader, 1024)
    if err != nil {
        panic(err)
    }

    pubS3FS := pki.PublicKey(rsaKey.PublicKey)

    superLargeFile := []byte("super large file contents")
    encBlock, err := pubS3FS.EncryptCBC(superLargeFile)
    if err != nil {
        panic(err)
    }

    // a randomly generated key (K) that's been that's been encrypted with your
    // and base64-encoded
    fmt.Println(encBlock.EncryptedSymmetricKey)

    // your data encrypted using a randomly generated key as input to the
    // AES-256 block cipher in CBC mode
    fmt.Println(encBlock.EncryptedBlob)
}
```<commit_msg>decrypt in example<commit_after># go-crypto [![Build Status](https://travis-ci.org/phylake/go-crypto.svg?branch=master)](https://travis-ci.org/phylake/go-crypto)

Go utilities for common cryptography tasks

## Examples

### Encrypt a large file with a public key and AES-256-CBC

```golang
package main

import (
    "crypto/rand"
    "crypto/rsa"
    "fmt"
    "github.com/phylake/go-crypto/pki"
)

func main() {
    rsaKey, err := rsa.GenerateKey(rand.Reader, 1024)
    if err != nil {
        panic(err)
    }

    privateKey := pki.PrivateKey(*rsaKey)
    publicKey := pki.PublicKey(rsaKey.PublicKey)

    superLargeFile := []byte("super large file contents")
    encBlock, err := publicKey.EncryptCBC(superLargeFile)
    if err != nil {
        panic(err)
    }

    // a randomly generated key (K) that's been that's been encrypted with your
    // and base64-encoded
    fmt.Println(encBlock.EncryptedSymmetricKey)

    // your data encrypted using a randomly generated key as input to the
    // AES-256 block cipher in CBC mode
    fmt.Println(encBlock.EncryptedBlob)

    // decrypt and print the original file
    superLargeFile2, err := privateKey.DecryptCBC(encBlock)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(superLargeFile2))
}

```

## Notable implementation details
- The only cipher used is 256 bit AES.
- The CBC block cipher mode is OpenSSL (aes-256-cbc) compatible. Both use SHA1 as the hash function.
{'fraction_non_alphanumeric': 0.1175996778091019, 'fraction_numerical': 0.01288763592428514, 'mean_word_length': 3.1331114808652245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 4, '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': '4451724', 'n_tokens_mistral': 862, 'n_tokens_neox': 792, 'n_words': 221}