function aesEncrypt(){
$data = openssl_encrypt('5ddbf06d-adfd-10f4-de2b-f39b13e8eb8d_1604996361','AES-128-ECB',decbin(1604996361));
echo 'encrypt='.$data.PHP_EOL;
return $data;
}
function aesDecrypt($secretData){
$data = openssl_decrypt($secretData,'AES-128-ECB',decbin(1604996361));
echo 'decrypt='.$data.PHP_EOL;
$arrU = explode('_',$data);
$uuid = $arrU[0];
echo 'decrypt11111='.$uuid.PHP_EOL;
}
加密 5ddbf06d-adfd-10f4-de2b-f39b13e8eb8d_1604996361
输出aZkNWORB4zD095e/GLIj0EL2Q20r7tcICMwZ9rRigwjAqhaSNJs7EcMYuKxNE1JT
https://www.php.net/manual/zh/function.openssl-encrypt.php
可知key
为php
里的decbin(1604996361)
,iv
为空串。
php在线 https://tool.lu/coderunner/ 知decbin(1604996361)
为字符串1011111101010100100110100001001
使用 https://github.com/WelkinXie/AESCipher-iOS 并改其内部kv
为空串
新建项目mac commandline
验证通过
#import <Foundation/Foundation.h>
#import <CommonCrypto/CommonCryptor.h>
NSString const *kInitVector = @"";
size_t const kKeySize = kCCKeySizeAES128;
NSData * cipherOperation(NSData *contentData, NSData *keyData, CCOperation operation) {
NSUInteger dataLength = contentData.length;
void const *initVectorBytes = [kInitVector dataUsingEncoding:NSUTF8StringEncoding].bytes;
void const *contentBytes = contentData.bytes;
void const *keyBytes = keyData.bytes;
size_t operationSize = dataLength + kCCBlockSizeAES128;
void *operationBytes = malloc(operationSize);
if (operationBytes == NULL) {
return nil;
}
size_t actualOutSize = 0;
CCCryptorStatus cryptStatus = CCCrypt(operation,
kCCAlgorithmAES,
kCCOptionECBMode | kCCOptionPKCS7Padding,
keyBytes,
kKeySize,
initVectorBytes,
contentBytes,
dataLength,
operationBytes,
operationSize,
&actualOutSize);
if (cryptStatus == kCCSuccess) {
return [NSData dataWithBytesNoCopy:operationBytes length:actualOutSize];
}
free(operationBytes);
operationBytes = NULL;
return nil;
}
NSString * aesEncryptString(NSString *content, NSString *key) {
NSCParameterAssert(content);
NSCParameterAssert(key);
NSData *contentData = [content dataUsingEncoding:NSUTF8StringEncoding];
NSData *keyData = [key dataUsingEncoding:NSUTF8StringEncoding];
NSData *encrptedData = cipherOperation(contentData, keyData, kCCEncrypt);
return [encrptedData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
}
int main(int argc, const char * argv[]) {
@autoreleasepool {
NSLog(@"---%@---", aesEncryptString(@"5ddbf06d-adfd-10f4-de2b-f39b13e8eb8d_1604996361", @"1011111101010100100110100001001"));
}
return 0;
}
网友评论