0

I have a string, this string needs to be Encoded using PHP. Then its sent to a site via GET and needs to be decoded on this site via Javascript.

Its totally ok that somebody can decode the string, but I need that nobody is able to generate a new encoded string.

Basically, everybody should be able to decode the string without any problems, but nobody should be able to encode a new string.

Lets make a example for explanation:

My string is "hello world" and encrypt it SOMEHOW and get "asdflpausoiwjuh" as result. Then I send this result to you guys and you know how to decrypt it to read the message. but nobody of you is able to make a new message that can be encrypted in the same way.

MUST:

  • Encrypted with PHP
  • Decrypted with Javascript
  • Lenght of the string before and after encryption must remain the same OR still guarantee a pretty short string that can be passed via GET to a page.
  • I must be the only one able to generate messages that are encrypted in this way.

EDIT: The encrypted text has a validity of about an hour and tehre will actually not be real interest to "crack" the system. so security is not my priority. what i really need is that 99% of the people wont be able to generate the string, and the 1% should have a hard time figuring out how to do it. for me that is safe enough. my problem is that whatever i think of putting into the javascript code, brings me to something that can be reverse engeneered.

6
  • If someone knows how to decrypt the string, why can't they do the reverse, that is encrypt the string back? Commented Feb 7, 2014 at 15:56
  • You should probably look into asymmetric encryption algorithms. Commented Feb 7, 2014 at 15:58
  • well usually its inverted.. everybody can encrypt and only one decrypt.. i need it the other way around.. Commented Feb 7, 2014 at 16:00
  • The equal-length requirement may be difficult to achieve. Perhaps crypto.stackexchange.com would be a better place to post your question. Commented Feb 7, 2014 at 16:01
  • 1
    @user2452250 Asymmetric encryption allows both. For your requirement, you encrypt with the private key, everyone can decrypt with the public key. Commented Feb 7, 2014 at 16:01

1 Answer 1

2

You might look into some entry-level explanation of public key cryptography. What you intend to do is a classical example, only in reverse. ;)

Most likely what you really want to do is sign a message. That means, you want to make sure any message comes from you and only you. Its public and needs not be encrypted, but you want recipients to know it was not altered in transit.

Here's a link to get you started:

http://en.wikipedia.org/wiki/Digital_signature

Sign up to request clarification or add additional context in comments.

1 Comment

True, but i need to preserve the length of the string. is there some example code you could provide to have something to work on? i dont know where to start at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.