Created
December 19, 2017 05:42
-
-
Save CodFrm/04adb64ea09e718fa48f3ab116f7448d to your computer and use it in GitHub Desktop.
PHP对接java的AES/ECB/PKCS5Padding加密方式
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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通用,未深究 | |
} | |
openssl_decrypt 的option没有OPENSSL_PKCS1_PADDING这个参数啊,这个参数不是openssl_public_decrypt的么?
你去看一下定义就知道了,OPENSSL_PKCS1_PADDING和OPENSSL_RAW_DATA恰好都是1
https://www.php.net/manual/en/function.openssl-get-cipher-methods.php
上面链接没有 aes-128-ecb 这种加密方式。不知道你测试通过了没?
https://www.php.net/manual/en/function.openssl-get-cipher-methods.php
上面链接没有 aes-128-ecb 这种加密方式。不知道你测试通过了没?
测试通过了的,请以实际环境为准
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
openssl_decrypt 的option没有OPENSSL_PKCS1_PADDING这个参数啊,这个参数不是openssl_public_decrypt的么?