Skip to content Skip to sidebar Skip to footer

Decrypting A String Encrypted On An Android Device

On an Android 4.4 device, a string has been encrypted using the org.springframework.security.crypto.encrypt.AndroidEncryptors class from the spring-android-auth 1.0.1.RELEASE modul

Solution 1:

on Android i'm using

compile group: 'org.springframework.security', name: 'spring-security-crypto', version: '3.1.0.RELEASE'

on Spring-Backend i'm using

compile"org.springframework.security:spring-security-core:4.2.3.RELEASE"

My Example for you looks like:

val password ="MY_PASSWORD"
val salt =KeyGenerators.string().generateKey()
val encryptor =Encryptors.text(password, salt)
val textToEncrypt ="kotlin-rocks"
val encryptedText = encryptor.encrypt(textToEncrypt)

val decryptor =Encryptors.text(password, salt)
val decryptedText = decryptor.decrypt(encryptedText)


println("Salt: \""+ salt +"\"")
println("Original text: \""+ textToEncrypt +"\"")
println("Encrypted text: \""+ encryptedText +"\"")
println("Decrypted text: \""+ decryptedText +"\"")

If you run the code on Android you will get the following random result:

Salt:"2578bfa1cb682f17"
Original text: "kotlin-rocks"
Encrypted text: "bdfdfff122accfadc0ad5449bb9c93ceedd2380b2e7f8cd19d2ce03daec4218e"
Decrypted text: "kotlin-rocks"

Now you have to send the salt and the encrypted text to the server. The server will use both of them and can now decrypt the password. The implementation of the cipher code can be the same.

Post a Comment for "Decrypting A String Encrypted On An Android Device"