Skip to content

soatok/hash-crypt

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 

Hash-Crypt

Linux Build Status License

Warning! This is an experimental design. Don't ever use this in production. It was created to demonstrate a concept for educational purposes. Just use libsodium.

A proof-of-concept for turning any arbitrary hash function into an AEAD cipher.

Usage:

<?php
declare(strict_types=1);

use ParagonIE\ConstantTime\Binary;
use Soatok\HashCrypt\{
    HashCrypt,
    Key
};

$key = Key::generate();
$hashCrypt = new HashCrypt('sha256', $key);

$message = 'This is a secret message';
$encrypted = $hashCrypt->encrypt($message);
$decrypted = $hashCrypt->decrypt($encrypted);
var_dump($encrypted === $decrypted); // bool(true)

### Messages can also have additional authenticated data attached to the ciphertext.
### This is used to calculate tha authentication tag, but is not included in the
### ciphertext message itself.

$ciphertext2 = $hashCrypt->encrypt($message, 'additional authenticated data');
var_dump(Binary::safeStrlen($encrypted) === Binary::safeStrlen($ciphertext2)); // bool(true)

try {
    $decrypted = $hashCrypt->decrypt($ciphertext2);
} catch (\Soatok\HashCrypt\CryptoException $ex) {
    // Invalid message authentication code.
    echo $ex->getMessage();
    exit(1);
}

Frequently Asked Questions

Is this SHA-256 Encryption?

SHA-256 isn't encryption. SHA-256 is a hash function.

I did build an AEAD cipher out of SHA-256.

Should I use this?

No.

Are you insane?!

Well, I am a furry...

About

A proof-of-concept for turning any arbitrary hash function into an AEAD cipher.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages