473,406 Members | 2,390 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Removing padded characters from AES encoding

3
Hello, thanks for this piece of code. I have a question. If encoding, if the last chunc is less then 16 signs, this will be filled with Nul chars. After decrypting the original string differs from the decrypted string in this NUL chars. How can that be avoided?
Cheers Astera

Moderator Note: Split from https://bytes.com/topic/access/insig...m-vba-vbscript
Mar 30 '20 #1
5 1364
Rabbit
12,516 Expert Mod 8TB
A common way of handling this is store the size of the message/file in the header. That way you know when to cut off the last block.

An unrelated but also common thing to do is to store a hash of the key, a hash of the message/file, and any nonces, salts, or initialization vectors you use. This allows you to verify that the correct password was entered and that the decoded message is correct.
Mar 30 '20 #2
astera
3
Thanks Rabbit for quick reaction.
When I have a string with Len=107 the last block is Len=11. Where do I have to cut? I tried to cut here:
This is your code:
Expand|Select|Wrap|Line Numbers
  1.        If Len(sTemp) < 16 Then
  2.                 For i = Len(sTemp) To 15
  3.                     sTemp = sTemp & Chr(0)
  4.                 Next
  5.             End If
This is what I have changed (iMaxLen=16)
Expand|Select|Wrap|Line Numbers
  1. 60            If Len(sTemp) < iMaxLen Then
  2.                   iMaxLen = Len(sTemp)
  3. '80                    sTemp = sTemp & Chr(0)
  4. '90                Next
  5. 100           End If
but then I get an error on line 120 if it exceed iMaxLen:
Expand|Select|Wrap|Line Numbers
  1. 110           For i = 0 To iMaxLen - 1
  2. 120               block(i) = Asc(Mid(sTemp, (i Mod 4) * 4 + (i \ 4) + 1, 1))
  3. 130           Next
Cheers Asterios
Mar 31 '20 #3
Rabbit
12,516 Expert Mod 8TB
I'm splitting this thread out as it's exceeding the scope of the article.

There's no need to cut the string at place where it's getting padded as the padding is necessary. You only need to strip out during decryption.

Since AES works on 16 byte blocks, if you mod the length by 16, that tells you how many bytes to get from the last block.
Apr 1 '20 #4
astera
3
Hello Rabbit,
you are right. If I want to decrypt a whole file or a string without the intention to add somethings later, the code works. I only need to cut the last NUL chars while decryption. So far so good.
What I want to achieve is to en-decrypt log-files. Means whenever a log-string will be added to the log-file I want to
  • encrypt the log-string
  • add it to the file
  • save the file
Next log-string need to be encrypted, added and save the file in the same manner.
But when I decrypt that log-file afterwards, the out put is not the same as the origin log-strings.
May be you have an idea to solve that.
By the way, Before I started to encrypt with your code I needed to change somethings to make it happen.
If you are interested, please let me know where to post or send.

Cheers Asterios
Apr 4 '20 #5
Rabbit
12,516 Expert Mod 8TB
But when I decrypt that log-file afterwards, the out put is not the same as the origin log-strings.
May be you have an idea to solve that.
The ideas to solve that are in my prior posts above. To repeat:

A common way of handling this is store the size of the message in the header. That way you know when to cut off the last block.

There's no need to cut the string at the place where it's getting padded for encryption as the padding is necessary. You only need to strip out during decryption.

Since AES works on 16 byte blocks, if you mod the length by 16, that tells you how many bytes to get from the last block.
Apr 5 '20 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: mr_burns | last post by:
Hi there, How do I remove space characters from a string using PHP? For example, the following string... ' hi there, my name is burnsy ' ....has spaces, at the edges and inbetween the...
2
by: matt | last post by:
I have an upload script for a photo and a caption. It all goes pear shaped when I upload a character like ' " or / \ | Is there anyway I can parse through the filename when submitting the form and...
2
by: Abby Lee | last post by:
I need to add and subtract transactions for each of our accounts within our Access DB for account reconciliation. Values found in our PdAmount field are either positive or negative. Positive...
1
by: Phil Amey | last post by:
In a web based form I am able to make sure that there is text in an input field but I want to restrict the user from using such characters as ~ # & ' How can I modify this JavaScript below to...
6
by: Peter | last post by:
Hello: How can I validate the character encoding of the textbox in a form? For instance, when the user fills out a form, I need to be sure that he is typing in English (I mean uses Latin...
3
by: David Lambert | last post by:
Hi, I have a text reader that is parsing a file, I have a number of lines with accents eg. "Herr Dietman Löflers (CEO)" my text reader returns: "Herr Dietman Lflers (CEO)", it drops all the...
2
by: Krzysiek | last post by:
Hello, in what code-page are characters stored in MSSQL tables? is it windows1250? -- Chris
8
by: Peter O'Reilly | last post by:
I have an HTML form with a textarea input box. When the user conducts a post request (e.g. clicks the submit button), an HTML preview page is presented to them with the information they have...
4
by: Peter Afonin | last post by:
Hello: How can I validate the character encoding of the textbox in ASP.Net form? For instance, when the user fills out a form, I need to be sure that he is typing in English (I mean uses Latin...
0
by: Benny the Guard | last post by:
I have a string value that may contain some unprintable characters. I am using the xml.sax.escape to remove the the <, > and & characters fine but it seems to leave in the \n characters. Later this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.