Coder Social home page Coder Social logo

p581581 / magiccrypt Goto Github PK

View Code? Open in Web Editor NEW

This project forked from magiclen/magiccrypt

0.0 2.0 0.0 52 KB

MagicCrypt is a Java/PHP library to encrypt/decrpyt strings or data using Advanced Encryption Standard(AES) algorithm. It supports CBC block cipher mode, PKCS5 padding and 128 or 256-bits key length. The encrypted data will be formatted to Base64 string.

Home Page: https://magiclen.org/aes/

Java 91.57% PHP 8.43%

magiccrypt's Introduction

MagicCrypt

Introduction

MagicCrypt is a Java/PHP library to encrypt/decrpyt strings or data using Advanced Encryption Standard(AES) algorithm. It supports CBC block cipher mode, PKCS5 padding and 128 or 256-bits key length. The encrypted data will be formatted to Base64 string.

Usage For Java

MagicCrypt Class

MagicCrypt class is in the org.magiclen.magiccrypt package. It can help you encrypt/decrpyt strings or data using Advanced Encryption Standard(AES) algorithm.

Initialize

You have to input your AES key and key length to construct MagicCrypt object. For example,

final MagicCrypt mc = new MagicCrypt("magickey", 256);

Note. MagicCrypt only supports 128 and 256-bits key length. The larger key length, the stronger security of course. The default length is 128 bits. If you want to use 256 bits in your Java Runtime Machine (JRE), you have to install Java Cryptography Extension (JCE) first.

By the way, if you want to change Initialization Vector(IV), you can set it by passing your IV string into the third parameter to the constructor of MagicCrypt object.

Encrypt

You can use encrypt method to encrypt any string or data. For example,

final MagicCrypt mc = new MagicCrypt("magickey", 256);
System.out.println(mc.encrypt("http://magiclen.org"));

The result is,

DS/2U8royDnJDiNY2ps3f6ZoTbpZo8ZtUGYLGEjwLDQ=

Decrypt

You can use decrypt method to decrypt any encrypted string or data. For example,

final MagicCrypt mc = new MagicCrypt("magickey", 256);
System.out.println(mc.decrypt("DS/2U8royDnJDiNY2ps3f6ZoTbpZo8ZtUGYLGEjwLDQ="));

The result is,

http://magiclen.org

Base64 Class

Base64 class is in the org.magiclen.magiccrypt package. It is a clone of an implementation of Base64 in Java 8 SE adjusted for the old Java versions lower than 8.

Usage For PHP

MagicCrypt.php

Initialize

require of include MagicCrypt.php into your PHP program. Then, you have to input your AES key and key length to construct MagicCrypt object. For example,

require('MagicCrypt.php');

$mc = new MagicCrypt('magickey', 256);

If you want to change Initialization Vector(IV), you can set it by passing your IV string into the third parameter to the constructor of MagicCrypt object.

Encrypt

You can use encrypt method to encrypt any string or data. For example,

$mc = new MagicCrypt('magickey', 256);
echo $mc->encrypt('http://magiclen.org');

The result is,

DS/2U8royDnJDiNY2ps3f6ZoTbpZo8ZtUGYLGEjwLDQ=

Decrypt

You can use decrypt method to decrypt any encrypted string or data. For example,

$mc = new MagicCrypt('magickey', 256);
echo $mc->decrypt('DS/2U8royDnJDiNY2ps3f6ZoTbpZo8ZtUGYLGEjwLDQ=');

The result is,

http://magiclen.org

License

Copyright 2015-2016 magiclen.org

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.

What's More?

Please check out our web page at

http://magiclen.org/aes/

magiccrypt's People

Contributors

magiclen avatar

Watchers

 avatar  avatar

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.