Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AES-CCM 及 AES-GCM ? #2

Open
puckyeh opened this issue Jan 30, 2019 · 12 comments
Open

AES-CCM 及 AES-GCM ? #2

puckyeh opened this issue Jan 30, 2019 · 12 comments

Comments

@puckyeh
Copy link

puckyeh commented Jan 30, 2019

我使用了你所提供的 cipher2 0.2.1這個 flutter plugin , 非常簡易好用!!
目前我需要 AES-CCM 及 AES-GCM 來做加密解密,
想請問一下, 你能夠提供並升級此插件嗎?

@shyandsy
Copy link
Owner

ok. I will publish a new version which support aes ccm and gcm net week.

我会在下周发一个新版本支持AES ccm和gcm。

@shyandsy
Copy link
Owner

shyandsy commented Jan 31, 2019

@puckyeh
hi, i published a new version to support GCM for android.

Could u help to test it on android?

if no problem I will implement the ios part

新版本支持android平台gcm加解密。可以帮测试下。
没有什么问题的话,我就开始实现ios系统支持了。

@puckyeh
Copy link
Author

puckyeh commented Feb 1, 2019

android gcm 加解密 測試看起來沒問題!!

@shyandsy
Copy link
Owner

shyandsy commented Feb 1, 2019 via email

@puckyeh
Copy link
Author

puckyeh commented Feb 1, 2019

我自行用 php 試著做 aes-128-gcm 的加解密
和你轉出來的結果好像不同耶!!

$plaintext = ('{"token":"ABCDEFGHIJKLMNOPQRSTUVWXYZ","device":"AABBCCDD"}');
$key = '8c775176c699f9cd';
$iv = '0000000756632532';
$cipher = "aes-128-gcm";

php 轉出來的結果是
yAChpzwcQ89E7IqvzBNU7Ty5evziE29hLn1VtYqTWUqewxD7jCY0Au2OeovyUlsB7wFTOVk97Q3rZKKMEvl3Je1j

用你的 lib 轉出來的結果是
YnT2s2JmGMXGgT12BT9pn5S6+nf/2A6KejUdyy7Yhq30HrLL2c/B6acdjgazJCQ1ngjuFHr6Zu5eXGGnb3WGN1s2lCs9WFjQje0=

@shyandsy
Copy link
Owner

shyandsy commented Feb 1, 2019

@puckyeh

明白你的问题了,我需要修改一下秘钥参数格式。兼容更多的表示方式

@shyandsy
Copy link
Owner

shyandsy commented Feb 2, 2019

@puckyeh
可以贴一下你的php加密代码么

@puckyeh
Copy link
Author

puckyeh commented Feb 2, 2019

加密
$ciphertext = openssl_encrypt($plaintext, $cipher, $key, $options=0, $iv, $tag);
解密
$original_plaintext = openssl_decrypt($ciphertext, $cipher, $key, $options=0, $iv, $tag);

@shyandsy
Copy link
Owner

shyandsy commented Feb 2, 2019

@puckyeh

麻烦贴完整可运行代码,不要让我猜参数,整理你的代码。

@puckyeh
Copy link
Author

puckyeh commented Feb 2, 2019

不好意思, 當時想貼完整的, 但都是亂碼, 就沒想那麼多了, 我重新貼!!
$tag 預設就是 null

$plaintext = ('{"token":"ABCDEFGHIJKLMNOPQRSTUVWXYZ","device":"AABBCCDD"}');
$key = '8c775176c699f9cd';
$iv = '0000000756632532';
$cipher = "aes-128-gcm";
$tag = null;
if (in_array($cipher, openssl_get_cipher_methods()))
{
$ciphertext = openssl_encrypt($plaintext, $cipher, $key, $options=0, $iv, $tag);
echo $ciphertext;
$original_plaintext = openssl_decrypt($ciphertext, $cipher, $key, $options=0, $iv, $tag);
echo $original_plaintext;
}

@puckyeh
Copy link
Author

puckyeh commented Feb 13, 2019

我剛剛才發現, 你的 nonce 有做過 base64 的編碼
所以我在 php 上的 $iv 也補做了 base64, 編碼出來的結果看起來對一半, 貼給你看看, 希望對你有幫助!!

以下為參數 :
$plaintext = '{"badgeCount":"3"}';
$key = '8c775176c699f9cd';
$iv = '0000000756632532';

php 的編碼結果
"pVlKqNVeHv06aENl2nau/n4M"

cipher2 的編碼結果
"pVlKqNVeHv06aENl2nau/n4M8G2uIl7vt0BFM7uFTtQb0Q==\n"

@shyandsy
Copy link
Owner

shyandsy commented Feb 13, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants