image path obfuscation

Posted in Uncategorized | No Comments »

Someone in my office asked me to hide image URL. The problem is, we’ve a bunch of pictures of students and we don’t want any one to download all of them. The pictures are named by student ID, so it will be easy to write a small code to iterate all ID and download all the pictures. That’s why we need to hide the image URL.

At first, I want to make a hash function. So, it will be harder to break. However, we need a storage to store all hash, either in database or in file, which is I don’t want to . So, hash is gone. The other choice is encryption.

What I did is to write two code, first one is to generate an encrypted text from student id. Then, the second code, convert the encrypted text back to id. So, the image URL will include the encrypted text instead of picture’s name. So, instead of

http://www.foo.com/image/512345.jpg

the url will be

http://www.foo.com/image/get_picture.php?hash=21342u987891234

To do this, I use mcrypt function in php to encrypt and decrypt, this is nothing special.

However, I feel like this method will be a victim of known-plaintext attack. Because the website that shows this picture also shows student ID and everyone can guess that the picture’s name should be the ID itself. So, I would like to change the key periodically. So, I make a cron script to change the encryption key every day. It will be harder to crack the encryption.

The code is here

It’s a rainy day.

Posted in Photography | No Comments »

เคลิ้ม

Posted in Photography | No Comments »

Some people

Posted in Video/Music | No Comments »

You told me I can be rich.
Well, some people live for the fortune, but I don’t…
You asked me if I want any things?
Well, some people think that the physical things define what’s within, but I don’t….
You asked me what I want?
Well, some people want it all, but I don’t want nothing at all.

I don’t want nothing at all if it ain’t you.

ขึ้นอยู่กับดินฟ้าอากาศ

Posted in Uncategorized | No Comments »

ค่าไฟที่บ้าน เป็นไปตามฤดูกาล

The confession of a lonely late night programmer ^_~

Posted in Uncategorized | No Comments »

my old ibook

Posted in Photography | No Comments »

ถ้าไม่นับว่าโลจิกบอร์ดพังในเดือนแรกที่ซื้อ ibook เครื่องนี้มีปัญหาน้อยมาก สำหรับโน้ตบุ๊คอายุเกือบเจ็ดปี ตอนนี้ก็ใช้งานได้ดีทีเดียว

หัวปลาแซลมอนต้มซีอิ้ว

Posted in Photography | No Comments »


Salmon head in soy sauce, originally uploaded by pruet.

Toto in BW

Posted in Photography | No Comments »


แหะ, originally uploaded by pruet.

Chiang Mai Now and Then

Posted in Photography | No Comments »


วัดกู่เต้า, originally uploaded by pruet.

More pictures : http://www.flickr.com/photos/pruet/sets/72157626152164236/