フィルターのクリア

How do to handle the case, when the string to be encrypted using AES is less than 16 bytes?

3 ビュー (過去 30 日間)
AES code requires the string to be 16 bytes. How do I handle a case, when the string to be converted is less than 16 bytes both during encryption and decryption? Appreciate, if you could paste the code snippet?
You may refer to AES code at http://buchholz.hs-bremen.de/aes/aes.htm
Thanks a lot!

採用された回答

Geoff Hayes
Geoff Hayes 2014 年 5 月 23 日
編集済み: Geoff Hayes 2014 年 5 月 23 日
If the string (to encrypt) is less than 16 bytes, then why not just pad with zeros? Looking at the documentation referenced from your above link ( http://buchholz.hs-bremen.de/aes/AES.pdf) the plaintext input to the cipher function is just an array of 16 doubles (presumably, the software only considers the first 8 bits from each double) converted from the plaintext string via hex2dec. So you could do something like the following with your plaintext hexadecimal string:
ptLen = length(plaintext); % get the length of the plaintext string
if ptLen>0 && ptLen<16
plaintext = [plaintext repmat({'00'},1,16-ptLen)]; % pad the plaintext
end % string with zeros
Now your plaintext string has length of 16, and the conversion from hexadecimal to decimal, and the encryption can proceed (as per the documentation).
The decryption shouldn't matter as the cipher text will be 16-bytes (I'm assuming this given my brief read of the document).
  4 件のコメント
Anis Zaitunah
Anis Zaitunah 2021 年 7 月 1 日
If the string (to encrypt) is more than 16 bytes, how to encryp?
Geoff Hayes
Geoff Hayes 2021 年 7 月 2 日
Anis - I think that would would encrypt every block of 16 bytes and then, when you have a block that is less than 16 bytes, pad it with zeros. Perhaps.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEncryption / Cryptography についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by