Skip to content

Instantly share code, notes, and snippets.

@haxianhe
Forked from CodFrm/aes_ecb_pkcs5.php
Created July 24, 2018 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haxianhe/22d72186c8b047500d52e2d0873ad7af to your computer and use it in GitHub Desktop.
Save haxianhe/22d72186c8b047500d52e2d0873ad7af to your computer and use it in GitHub Desktop.
PHP对接java的AES/ECB/PKCS5Padding加密方式
<?php
/**
*============================
* author:Farmer
* time:2017/12/19
* blog:blog.icodef.com
* function:加密方式
*============================
*/
/**
* 与java等的aes/ecb/pcks5加密一样效果
* @author Farmer
* @param $data
* @param $key
*/
function encrypt($data, $key) {
return base64_encode(openssl_encrypt($data, 'aes-128-ecb', $key, OPENSSL_PKCS1_PADDING));//OPENSSL_PKCS1_PADDING 不知道为什么可以与PKCS5通用,未深究
}
/**
* 可以解密java等的aes/ecb/pcks5加密的内容
* @author Farmer
* @param $data
* @param $key
*/
function decrypt($data, $key) {
return openssl_decrypt(base64_decode($data), 'aes-128-ecb', $key, OPENSSL_PKCS1_PADDING);//OPENSSL_PKCS1_PADDING 不知道为什么可以与PKCS5通用,未深究
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment