2

I'm using framework laravel for encryption some string, in my laravel i write the code like this :

public function getBankNameAttribute(){
    return Crypt::encrypt($this->attributes['bank_name']);
}

The result is String 'abc' encrypted to String

'eyJpdiI6InBxeTlKOVdFQ1FoN2hGNDdPSTJZUnc9PSIsInZhbHVlIjoiVzlQYVpsSlptUHF6QUMwalM0c21vZz09IiwibWFjIjoiNGFlYmY3OTk2MDUyYTcwMzMxMGYzYmQzODRhODUyNWRlZjMzNjNmMDU5NTJiMDg2NmJjNzhkYjI5NTkzYzI1YSJ9'

The return of the encrypt is always different because of generate IV from laravel.If the output is always different,how can i decrypt the string outside laravel. Especially for Android.

I have searching the whole documentation on Google, but no one made it for Android. Thanks in advance.

Anirudh Sharma
  • 7,968
  • 13
  • 40
  • 42

1 Answers1

1

The link in the comment by TheAlpha should be enough. I'll just add that if you Base64 decode the string 'eyJpdiI6InBxeTlKOVdFQ1FoN2hGNDdPSTJZUnc9PSIsInZhbHVlIjoiVzlQYVpsSlptUHF6QUMwalM0c21vZz09IiwibWFjIjoiNGFlYmY3OTk2MDUyYTcwMzMxMGYzYmQzODRhODUyNWRlZjMzNjNmMDU5NTJiMDg2NmJjNzhkYjI5NTkzYzI1YSJ9' (for instance using https://www.base64decode.org/) you will get a JSON file with three values:

  • iv: Initial Vector - used to generate randomness when encrypting - needed to decrypt
  • value: the value that you actually want to decrypt - you need the iv and the secret key used to encrypt to actually decrypt it
  • mac: you can use to check that the value has not been tampered with. This optional but recommended.

See also: How to decrypt in Java (Android) text that was encrypted with Crypt in Laravel?

ioss
  • 105
  • 1
  • 10