Issue
I am writing a Kotlin AES decrypter and because of this I am using the Base64.decode function. However I cannot solve the reference error of the Base64 class. This is not an Android app, but a Kotlin Console Application that I run on my Windows machine in IntelliJ.
- Kotlin 1.6
- IDE: IntelliJ 2021.2.3
- JVM 1.6.0
- jvmTarget 1.8
My code:
import java.util.*
import javax.crypto.spec.IvParameterSpec
class test {
fun test(){
val ivParameterSpec = IvParameterSpec(Base64.decode("iv", Base64.DEFAULT))
}
}
I've also tried:
import java.util.Base64
import javax.crypto.spec.IvParameterSpec
class test {
fun test(){
val ivParameterSpec = IvParameterSpec(Base64.decode("iv", Base64.DEFAULT))
}
}
Both gives the error:
Unresolved reference: decode'
and
Unresolved reference: DEFAULT
Solution
Base64.decode belongs to android.util package, which you can only use in an Android application.
For using Base64 decoder in an intellij kotlin project, use Base64 decoder provided in java.util package.
Base64.getDecoder().decode("iv")
Answered By - Praveen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.