Git Product home page Git Product logo

urlcrypt's Introduction

URLCrypt

Ever wanted to securely transmit (not too long) pieces of arbitrary binary data in a URL? URLCrypt makes it easy.

This class is based on the URLCrypt from Aaron Francis and forked from https://github.com/atrapalo/URLcrypt.

URLCrypt uses 256-bit AES symmetric encryption to securely encrypt data, and encodes and decodes Base 32 strings that can be used directly in URLs.

This can be used to securely store user ids, download expiration dates and other arbitrary data like that when you access a web application from a place that doesn't have other authentication or persistence mechanisms (like cookies):

  • Loading a generated image from your web app in an email
  • Links that come with an expiration date (à la S3)
  • Mini-apps that don't persist data on the server

Important: As a general guideline, URL lengths shouldn't exceed about 2000 characters in length, as URLs longer than that will not work in some browsers and with some (proxy) servers. This limits the amount of data you should store with URLCrypt.

Patches are welcome; please include tests!

Requirements

URLCrypt requires PHP >= 8.0 as well as the openssl PHP extension.

Installation

You can install URLCrypt via Composer with composer require dendreo/urlcrypt or by adding the following to your composer.json file:

{
	"require": {
		"dendreo/urlcrypt": "^2.0"
	}
}

Usage

use Atrapalo\UrlCrypt;

$urlCrypt = new UrlCrypt(); // Or $urlCrypt = UrlCrypt::getInstance()

// encoding without encryption. (don't use for anything sensitive)
$encoded = $urlCrypt->encode('Atrapalo');	// --> "3f5h2ylqmfwg9"
$decoded = $urlCrypt->decode('3f5h2ylqmfwg9');	// --> "Atrapalo"

// encrypting and encoding
$key = 'bcb04b7e103a0cd8b54763051cef08bc55abe029fdebae5e1d417e2ffb2a00a3';
$encrypted = $urlCrypt->encrypt('Atrapalo', $key);
		// --> 'xApfAdvAxg55jvk75y5n2d26xrhv3qtgfmxAmq53mf1t5'
$decrypted = $urlCrypt->decrypt('xApfAdvAxg55jvk75y5n2d26xrhv3qtgfmxAmq53mf1t5', $key)
		// --> 'Atrapalo'

Note that your key has to be a lower-case hex string.

Why not Base 64?

URLCrypt uses a modified Base 32 algorithm that doesn't use padding characters, and doesn't use vowels to avoid bad words in the generated string.

Base64 results in ugly URLs, since many characters need to be URL escaped.

Development

Clone the repository and do a composer install in the root directory of the library to install the development dependencies. Run the tests with phpunit from the root directory.

License

This library is licensed under the MIT License - see the COPYING file for details.

urlcrypt's People

Contributors

simon-bee avatar

Stargazers

Juan Timaná avatar

Watchers

Etienne Depaulis avatar Hadrien avatar

urlcrypt's Issues

Cannot install this package with composer

I've tried installing this package with composer without success. I get the following error message:

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Root composer.json requires dendreo/urlcrypt, it could not be found in any version, there may be a typo in the package name.

I also checked and this hasn't been submitted to https://packagist.org/

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.