[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Encrypting a short string?

erikcw

2/11/2008 7:46:00 PM

Hi,

I'm trying to devise a scheme to encrypt/obfuscate a short string that
basically contains the user's username and record number from the
database. I'm using this encrypted string to identify emails from a
user. (the string will be in the subject line of the email).

I'm trying to figure out which approach I should use to encrypt the
data. The string will be less than 20 characters long, and I'd like
the encrypted version to be about the same size.

I tried DES in the Crypto module, but the cipher text was to long to
be usable in this case.

Any suggestions?

Thanks!
19 Answers

marek.rocki

2/11/2008 8:08:00 PM

0

erikcw napisal(a):
> Hi,
>
> I'm trying to devise a scheme to encrypt/obfuscate a short string that
> basically contains the user's username and record number from the
> database. I'm using this encrypted string to identify emails from a
> user. (the string will be in the subject line of the email).
>
> I'm trying to figure out which approach I should use to encrypt the
> data. The string will be less than 20 characters long, and I'd like
> the encrypted version to be about the same size.
>
> I tried DES in the Crypto module, but the cipher text was to long to
> be usable in this case.
>
> Any suggestions?
>
> Thanks!

How about:
>>> hashlib.sha256("john.smith@example.com|2937267834").hexdigest()[:20]

Regards,
Marek

erikcw

2/11/2008 8:12:00 PM

0

On Feb 11, 3:07 pm, marek.ro...@wp.pl wrote:
> erikcw napisal(a):
>
>
>
> > Hi,
>
> > I'm trying to devise a scheme to encrypt/obfuscate a short string that
> > basically contains the user's username and record number from the
> > database. I'm using this encrypted string to identify emails from a
> > user. (the string will be in the subject line of the email).
>
> > I'm trying to figure out which approach I should use to encrypt the
> > data. The string will be less than 20 characters long, and I'd like
> > the encrypted version to be about the same size.
>
> > I tried DES in the Crypto module, but the cipher text was to long to
> > be usable in this case.
>
> > Any suggestions?
>
> > Thanks!
>
> How about:
>
> >>> hashlib.sha256("john.sm...@example.com|2937267834").hexdigest()[:20]
>
> Regards,
> Marek

Thanks Marek,

But that can't be reversed, right? I'd like to be able to decrypt the
data instead of having to store the hash in my database...

Paul Rubin

2/11/2008 8:24:00 PM

0

erikcw <erikwickstrom@gmail.com> writes:
> database. I'm using this encrypted string to identify emails from a
> user. (the string will be in the subject line of the email).

1. I hope you're not trying to spam anyone.
2. What happens if the user edits the subject line?

> I'm trying to figure out which approach I should use to encrypt the
> data. The string will be less than 20 characters long, and I'd like
> the encrypted version to be about the same size.

Under normal security requirements you cannot do this. The ciphertext
has to be longer than the plaintext since you don't want the opponent
to be able to tell whether two plaintexts are the same. Therefore you
have to attach some random padding to each plaintext. Also, you
presumably want the ciphertext to be encoded as printing characters,
while normally you'd treat the input as binary, so there is some
further expansion.

marek.rocki

2/11/2008 9:07:00 PM

0

erikcw napisal(a):
> But that can't be reversed, right? I'd like to be able to decrypt the
> data instead of having to store the hash in my database...
In such case it seems you have no choice but to use a symmetric
encryption algorithm - in other words, your original method. If the
strings are ~20 bytes long (3 DES blocks), then the base64-encoded
ciphertext will have 32 characters. In case of AES, that'll be up to
45 characters. Wouldn't such length be acceptable?

Paul Rubin napisal(a):
> 2. What happens if the user edits the subject line?
> Under normal security requirements you cannot do this. The ciphertext
> has to be longer than the plaintext since you don't want the opponent
> to be able to tell whether two plaintexts are the same. Therefore you
> have to attach some random padding to each plaintext. Also, you
> presumably want the ciphertext to be encoded as printing characters,
> while normally you'd treat the input as binary, so there is some
> further expansion.
If what erikcw is looking for is a cryptographically secure protocol,
there are more things to be careful about, like authentication or
replay attacks. But indeed, I'm wondering now what his use-case is.
> I'm using this encrypted string to identify emails from a
> user. (the string will be in the subject line of the email).
Why not use "From" field to identify emails from a particular user?

Regards,
Marek

erikcw

2/11/2008 9:19:00 PM

0

On Feb 11, 4:07 pm, marek.ro...@wp.pl wrote:
> erikcw napisal(a):> But that can't be reversed, right? I'd like to be able to decrypt the
> > data instead of having to store the hash in my database...
>
> In such case it seems you have no choice but to use a symmetric
> encryption algorithm - in other words, your original method. If the
> strings are ~20 bytes long (3 DES blocks), then the base64-encoded
> ciphertext will have 32 characters. In case of AES, that'll be up to
> 45 characters. Wouldn't such length be acceptable?
>
> Paul Rubin napisal(a):> 2. What happens if the user edits the subject line?
> > Under normal security requirements you cannot do this. The ciphertext
> > has to be longer than the plaintext since you don't want the opponent
> > to be able to tell whether two plaintexts are the same. Therefore you
> > have to attach some random padding to each plaintext. Also, you
> > presumably want the ciphertext to be encoded as printing characters,
> > while normally you'd treat the input as binary, so there is some
> > further expansion.
>
> If what erikcw is looking for is a cryptographically secure protocol,
> there are more things to be careful about, like authentication or
> replay attacks. But indeed, I'm wondering now what his use-case is.> I'm using this encrypted string to identify emails from a
> > user. (the string will be in the subject line of the email).
>
> Why not use "From" field to identify emails from a particular user?
>
> Regards,
> Marek

In essence what I'm doing is trying to manage tickets for a helpdesk.
I want the ticket identifier to be short enough to fit in the subject
line along with the normal subject chosen by the user. So
cryptographic security isn't really important. I can't use the from:
field because a single user could have multiple tickets.

Martin Marcher

2/11/2008 10:00:00 PM

0

Hi,

On 2/11/08, erikcw <erikwickstrom@gmail.com> wrote:
> In essence what I'm doing is trying to manage tickets for a helpdesk.
> I want the ticket identifier to be short enough to fit in the subject
> line along with the normal subject chosen by the user. So
> cryptographic security isn't really important. I can't use the from:
> field because a single user could have multiple tickets.

I've always wondered why such systems don't use the Message-ID or
Reference headers - I know they aren't preserved by all mailers but I
think that having this info in the subject line is

a) visually disturbing (subjective)
b) I guess that the risk of a user modifying the subject line is the
same than finding a programm that doesn't to some extent honor the
headers i mentioned...
<flame>
c) Personally whenever I find a mail that says please keep this in the
subject I delete that number on purpose...
</flame>

martin
--
http://noneisyours.ma...
https://twitter.com/Mar...
http://www.xing.com/profile/Mart...
http://www.linkedin.com/in/mar...

You are not free to read this message,
by doing so, you have violated my licence
and are required to urinate publicly. Thank you.

Gabriel Genellina

2/11/2008 10:16:00 PM

0

En Mon, 11 Feb 2008 19:19:00 -0200, erikcw <erikwickstrom@gmail.com>
escribió:

> In essence what I'm doing is trying to manage tickets for a helpdesk.
> I want the ticket identifier to be short enough to fit in the subject
> line along with the normal subject chosen by the user. So
> cryptographic security isn't really important. I can't use the from:
> field because a single user could have multiple tickets.

And you don't like [bug12345] or even [12345]? To the user, it's a lot
clear its purpose, and anybody will understand what you mean if you say
"Please maintain the bug number in the subject line" or similar.

--
Gabriel Genellina

Carl Banks

2/11/2008 10:18:00 PM

0

On Feb 11, 4:19 pm, erikcw <erikwickst...@gmail.com> wrote:
> On Feb 11, 4:07 pm, marek.ro...@wp.pl wrote:
> > erikcw napisal(a):> But that can't be reversed, right? I'd like to be able to decrypt the
> > > data instead of having to store the hash in my database...
>
> > In such case it seems you have no choice but to use a symmetric
> > encryption algorithm - in other words, your original method. If the
> > strings are ~20 bytes long (3 DES blocks), then the base64-encoded
> > ciphertext will have 32 characters. In case of AES, that'll be up to
> > 45 characters. Wouldn't such length be acceptable?
>
> > Paul Rubin napisal(a):> 2. What happens if the user edits the subject line?
> > > Under normal security requirements you cannot do this. The ciphertext
> > > has to be longer than the plaintext since you don't want the opponent
> > > to be able to tell whether two plaintexts are the same. Therefore you
> > > have to attach some random padding to each plaintext. Also, you
> > > presumably want the ciphertext to be encoded as printing characters,
> > > while normally you'd treat the input as binary, so there is some
> > > further expansion.
>
> > If what erikcw is looking for is a cryptographically secure protocol,
> > there are more things to be careful about, like authentication or
> > replay attacks. But indeed, I'm wondering now what his use-case is.> I'm using this encrypted string to identify emails from a
> > > user. (the string will be in the subject line of the email).
>
> > Why not use "From" field to identify emails from a particular user?
>
> > Regards,
> > Marek
>
> In essence what I'm doing is trying to manage tickets for a helpdesk.
> I want the ticket identifier to be short enough to fit in the subject
> line along with the normal subject chosen by the user. So
> cryptographic security isn't really important. I can't use the from:
> field because a single user could have multiple tickets.

Shouldn't you have a database associating a ticket ID with an email
address (among other things)?


Carl Banks

Paul Rubin

2/11/2008 11:17:00 PM

0

erikcw <erikwickstrom@gmail.com> writes:
> In essence what I'm doing is trying to manage tickets for a helpdesk.
> I want the ticket identifier to be short enough to fit in the subject
> line along with the normal subject chosen by the user.

I think you should use a database to maintain the email addresses
since you already have to maintain the contents and history of the
help ticket anyway. If the contents of the database is private, then
assign the ticket numbers in an unpredictable sequence--I can tell you
how to do that cryptographically if you want (I've posted code for it
a few times before). That is to stop users from guessing ticket
numbers that are valid but belong to other users. If it's a public
database (e.g. a bug tracker for a free software project) or if
accessing a particular ticket needs a user credential associated with
that ticket, then you may as well use sequential numbers.

Lie Ryan

2/16/2008 12:14:00 PM

0

On Feb 12, 2:45 am, erikcw <erikwickst...@gmail.com> wrote:
> Hi,
>
> I'm trying to devise a scheme to encrypt/obfuscate a short string that
> basically contains the user's username and record number from the
> database.  I'm using this encrypted string to identify emails from a
> user. (the string will be in the subject line of the email).
>
> I'm trying to figure out which approach I should use to encrypt the
> data.  The string will be less than 20 characters long, and I'd like
> the encrypted version to be about the same size.
>
> I tried DES in the Crypto module, but the cipher text was to long to
> be usable in this case.
>
> Any suggestions?
>
> Thanks!

There is a simple encryption, called ROT13 (Rotate 13). This is very
unsecure for any cryptographical purpose, but enough to make
uninformed user to think it's just a random piece of letters.

The ROT13 is done by adding 13 to each character, so
A => N,
B => O,
C => P,
D => Q, etc

the neat trick to this encryption is the algorithm is really simple
and you don't need a separate decoding algorithm as text ==
ROT13(ROT13(text)). This algorithm also guarantees that any two
different text would have two different ciphertext