Giter Club home page Giter Club logo

mine's Introduction

Minimal and single-header cryptography library (AES, RSA, Base16, Base64, ZLib)

Apache 2.0

Mine is fast, memory-efficient, single-header minimal cryptography implementation for small-medium projects that cannot afford to link to external libraries.

Overview

It all started with ripe that depends on third-party library (initially OpenSSL then Crypto++) linked statically. However after deploying residue with ripe to older distributions of linux, we learnt that portability is an issue for ripe as minimal library (because of it's dependencies). So we started to implement standards forming Mine.

I was very careful with my implementations and have over 50 test cases in-place.

Installation (API)

Simply copy mine.h and mine.cc from package/ directory to your project or your local machine.

Alternatively, feel free to link it as shared or static library (you will need to compile yourself)

Installation (CLI Tool)

You can either download binary for your platform via releases page or using NPM

npm install -g mine-linux@latest
sudo ln -s `which mine-linux` /usr/local/bin/mine
npm install -g mine-darwin@latest
sudo ln -s `which mine-darwin` /usr/local/bin/mine

Features

Mine supports following features:

This is what we are aiming for minimal crypto library.

Notes

  • It is natively developed on macOS and Linux operating systems
  • It is fast with compiler optimization level 1 (or higher)
  • You need to implement BigNumber to use RSA, for unit tests we use Integer from Crypto++
  • RSA currently does not support signing & verification or reading keys from PEM files

Quick Reference

Base16

  • mine::Base16::encode(str);
  • mine::Base16::encode(str.begin(), str.end());
  • mine::Base16::decode(encoding);

Base64

  • mine::Base64::encode(str);
  • mine::Base64::encode(str.begin(), str.end());
  • mine::Base64::decode(encoding);
  • mine::Base64::decode(encoding.begin(), encoding.end());
  • mine::Base64::expectedLength(n);

AES

std::string random256BitKey = mine::AES::generateRandomKey(256);

mine::AES aesManager;
aesManager.encrypt(b16Input, hexKey, mine::MineCommon::Encoding::Base16, mine::MineCommon::Encoding::Base64); // takes base16, encrypts and returns base64

aesManager.setKey(random256BitKey); // now use this key
aesManager.encr(b16Input, mine::MineCommon::Encoding::Base16, mine::MineCommon::Encoding::Base64); // don't need key with requests
aesManager.decr(b64Input, mine::MineCommon::Encoding::Base64, mine::MineCommon::Encoding::Raw); // Returns raw string

ZLib

  • mine::ZLib::compressString(str);
  • mine::ZLib::decompressString(str);
  • mine::ZLib::decompressFile(outputFile, inputFile);

Contribution

You can contribute to the project by testing on various platforms (e.g, Windows, Android etc)

License

Copyright 2017-present @abumq (Majid Q.)

https://github.com/abumq/mine

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

mine's People

Contributors

abumq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mine's Issues

base64 not work well on vc2019

Expression: cannot seek string iterator after end

The program is normal under the clang compiler, but on vc2019, Microsoft will report an error on the judgment condition of your "for" statement. If the judgment of the maximum pointer of the iterator exceeds the error, the debug channel will report an error, and the output of the Release channel will be abnormal.
Assuming the string length is "length", then it is normal when you execute begin+length<end, but after each round of the loop, the pointer is shifted back by 3 bits, then begin+length+1<end and begin+length+2<end two judgment statements will report an error.

I have a solution:
Change
for (auto it = begin; it < end; it += 3) {
to

auto length = end - begin;
for (auto i = 0; i < length; i += 3) {
				auto it = begin + i;

Change

if (it + 1 < end) {
if (it + 2 < end) {

to

if (i + 1 < length) {
if (i + 2 < length) {

Personally think this is the easiest solution.

AES encryption discrepancy

AES encryption is broken in some cases

Parameters

INPUT:

{"status":0,"ack":1,"flags":2001,"max_bulk_size":50,"server_info":{"version":"2.1.1-dev-debug"},"key":"141E4B143B314C71203E43481F1566504B3F52665847141F02104335650C5315","client_id":"muflihun00102030","logging_port":8778,"age":240,"date_created":1520477743}

KEY: 141E4B143B314C71203E43481F1566504B3F52665847141F02104335650C5315
IV: 3E552F2851473510663466583C084D29

Reproduce

## mine
echo '{"status":0,"ack":1,"flags":2001,"max_bulk_size":50,"server_info":{"version":"2.1.1-dev-debug"},"key":"141E4B143B314C71203E43481F1566504B3F52665847141F02104335650C5315","client_id":"muflihun00102030","logging_port":8778,"age":240,"date_created":1520477743}' | mine -e --aes --key 141E4B143B314C71203E43481F1566504B3F52665847141F02104335650C5315 --iv 3E552F2851473510663466583C084D29 --base64

## ripe
echo '{"status":0,"ack":1,"flags":2001,"max_bulk_size":50,"server_info":{"version":"2.1.1-dev-debug"},"key":"141E4B143B314C71203E43481F1566504B3F52665847141F02104335650C5315","client_id":"muflihun00102030","logging_port":8778,"age":240,"date_created":1520477743}' | ripe -e --aes --key 141E4B143B314C71203E43481F1566504B3F52665847141F02104335650C5315 --iv 3E552F2851473510663466583C084D29 --base64

Output

xhlE7aSsuVtzKBSNQU8eI0A81/HQ2O60YxYRXNjERTNCymJLkAbBYPlfO/wJKWfxbSPFMt0bt0mhyKoHzDsnOOdNkY1iUX99D17LM4pSzpC5iRsxoHPyx6Bp5huZtJ9dZRLom22017fFlmuW8LGVhWt5NsfR/2bwcZOICRnKMXEg06YVsvSOBMKhBtoqpzw+IWgzJxN7GZzZifsIGWvb9OMLiTufG+dMl+92mdf3EG1t7z+SWErcAX4PaNNYSl8cZDg13d2hyoeW2NGis2ga/XL+c2qIWBNbTkZqJFtThrT/Fz20FLnhJjVbmMhCcXo/lsEcF74OWtkfAvxyKGoHuQ==

or

C61944EDA4ACB95B7328148D414F1E23403CD7F1D0D8EEB46316115CD8C4453342CA624B9006C160F95F3BFC092967F16D23C532DD1BB749A1C8AA07CC3B2738E74D918D62517F7D0F5ECB338A52CE90B9891B31A073F2C7A069E61B99B49F5D6512E89B6DB4D7B7C5966B96F0B195856B7936C7D1FF66F07193880919CA317120D3A615B2F48E04C2A106DA2AA73C3E21683327137B199CD989FB08196BDBF4E30B893B9F1BE74C97EF7699D7F7106D6DEF3F92584ADC017E0F68D3584A5F1C643835DDDDA1CA8796D8D1A2B3681AFD72FE736A8858135B4E466A245B5386B4FF173DB414B9E126355B98C842717A3F96C11C17BE0E5AD91F02FC72286A07B9

Expected Output

xhlE7aSsuVtzKBSNQU8eI0A81/HQ2O60YxYRXNjERTNCymJLkAbBYPlfO/wJKWfxbSPFMt0bt0mhyKoHzDsnOOdNkY1iUX99D17LM4pSzpC5iRsxoHPyx6Bp5huZtJ9dZRLom22017fFlmuW8LGVhWt5NsfR/2bwcZOICRnKMXEg06YVsvSOBMKhBtoqpzw+IWgzJxN7GZzZifsIGWvb9OMLiTufG+dMl+92mdf3EG1t7z+SWErcAX4PaNNYSl8cZDg13d2hyoeW2NGis2ga/XL+c2qIWBNbTkZqJFtThrT/Fz20FLnhJjVbmMhCcXo/lsEcF74OWtkfAvxyKGoHuTFFrw5fRgqIGkLqgTEgmBU=

or

C61944EDA4ACB95B7328148D414F1E23403CD7F1D0D8EEB46316115CD8C4453342CA624B9006C160F95F3BFC092967F16D23C532DD1BB749A1C8AA07CC3B2738E74D918D62517F7D0F5ECB338A52CE90B9891B31A073F2C7A069E61B99B49F5D6512E89B6DB4D7B7C5966B96F0B195856B7936C7D1FF66F07193880919CA317120D3A615B2F48E04C2A106DA2AA73C3E21683327137B199CD989FB08196BDBF4E30B893B9F1BE74C97EF7699D7F7106D6DEF3F92584ADC017E0F68D3584A5F1C643835DDDDA1CA8796D8D1A2B3681AFD72FE736A8858135B4E466A245B5386B4FF173DB414B9E126355B98C842717A3F96C11C17BE0E5AD91F02FC72286A07B93145AF0E5F460A881A42EA8131209815

Difference is last few bits TFFrw5fRgqIGkLqgTEgmBU=

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.