openresty / encrypted-session-nginx-module

encrypt and decrypt nginx variable values
http://openresty.org
195 stars 52 forks source link

Encryption/Decryption Method #14

Open Roycohen opened 7 years ago

Roycohen commented 7 years ago

Hi There,

Assume I want to use this library and to decrypt and encrypt more things in PHP. How can I achieve it?

What is the encryption method? Do you have any PHP code example or can you please assist me in building one, using mcrypt or something.

Thanks

agentzh commented 7 years ago

@Roycohen The simplest way is just to write a simple PHP C extension library including the core C functions for encryption/decryption in this nginx C module.

siberex commented 7 years ago

@Roycohen use this snippet: https://gist.github.com/siberex/ee135b2d28b3b4be77c5

This is a php code to encrypt and decrypt data in encrypted-session-nginx-module compatible way. So, you can encrypt with php and decrypt with nginx module, and vice versa.

naviocean commented 7 years ago

Hello @siberex, Do you have Nodejs code?

siberex commented 7 years ago

@naviocean I don't have one. But you can easily transcribe it from php using either native NodeJS Crypto module or mcrypt npm package. Just keep in mind that nginx module does not use "true" HMAC, but simple md5 of message instead (see comments in my gist).