Git Product home page Git Product logo

php-java-aes-encrypt-decrypt's Introduction

PHP-Java-AES-Encrypt-Decrypt

To encrypt and decrypt text using AES/ECB/PKCS5Padding encryption algorithm, and pass data AES encrypted between PHP and Java. Two output types can be used in encryption and decryption: Base64, Hexadecimal.

AESUtil.java Dependencies & environment

AESUtil5.php Dependencies & environment

  • None
  • PHP Version: 5.x 7.0

AESUtil7.php Dependencies & environment

  • OpenSSL
  • PHP Version: 5.x 7.0 7.1 7.2

How to Use?

  1. Please see the samples below.
  2. Call decryptHexStr() to decrypt a ciphertext which is encrypted by encryptHexStr().
  3. Call decryptBase64() to decrypt a ciphertext which is encrypted by encryptBase64().

Java Test Preview:

public static void main (String [] args) {
        //AES only supports key sizes of 16, 24 or 32 bytes.
        String key = "s+FZFDjBKMUVDpu=";
        String plainText = "abcdef";

        String ciphertextBase64 = AESUtil.encryptBase64(plainText,key);
        String plaintextBase64 = AESUtil.decryptBase64(ciphertextBase64,key);

        String ciphertextHexStr = AESUtil.encryptHexStr(plainText,key);
        String plaintextHexStr = AESUtil.decryptHexStr(ciphertextHexStr,key);

        System.out.println(ciphertextBase64);//output: /s9PA4KQBKUhRPJDp+v3UA==
        System.out.println(plaintextBase64);//output: abcdef
        
        System.out.println(ciphertextHexStr);//output: FECF4F03829004A52144F243A7EBF750
        System.out.println(plaintextHexStr);//output: abcdef
}

PHP Test Preview:

<?php
  include 'AESUtil5.php';
  
  //AES only supports key sizes of 16, 24 or 32 bytes.
  $key = "s+FZFDjBKMUVDpu=";
  $plaintext = "abcdef";
  
  $ciphertextBase64 = AESUtil::encryptBase64($plaintext, $key);
  $plaintextBase64 = AESUtil::decryptBase64($ciphertextBase64, $key);
  
  $ciphertextHexStr = AESUtil::encryptHexStr($plaintext, $key);
  $plaintextHexStr = AESUtil::decryptHexStr($ciphertextHexStr, $key);
  
  
  echo $ciphertextBase64."<br/>";//output: /s9PA4KQBKUhRPJDp+v3UA==
  echo $plaintextBase64."<br/>";//output: abcdef
  
  echo $ciphertextHexStr."<br/>";//output: fecf4f03829004a52144f243a7ebf750
  echo $plaintextHexStr."<br/>";//output: abcdef
?>
<?php
  include 'AESUtil7.php';
  
  //AES only supports key sizes of 16, 24 or 32 bytes.
  $key = "s+FZFDjBKMUVDpu=";
  $plaintext = "abcdef";
  
  $ciphertextBase64 = AESUtil::encryptBase64($plaintext, $key);
  $plaintextBase64 = AESUtil::decryptBase64($ciphertextBase64, $key);
  
  $ciphertextHexStr = AESUtil::encryptHexStr($plaintext, $key);
  $plaintextHexStr = AESUtil::decryptHexStr($ciphertextHexStr, $key);
  
  
  echo $ciphertextBase64."<br/>";//output: /s9PA4KQBKUhRPJDp+v3UA==
  echo $plaintextBase64."<br/>";//output: abcdef
  
  echo $ciphertextHexStr."<br/>";//output: fecf4f03829004a52144f243a7ebf750
  echo $plaintextHexStr."<br/>";//output: abcdef
?>

php-java-aes-encrypt-decrypt's People

Contributors

ggchar avatar

Watchers

James Cloos avatar Tirapong Chaiyakun 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.