由于我们学校的网站太难使用,go 年我决定写一个手机应用程序,以便有更好的用户体验. 我已经使用了JSoup和其他实用程序来制作它.
我发现最近它的使用难度要大得多,网站上有更多的身份验证页面. 我花了一整天的时间来了解如何将代码从JS翻译成Kotlin.
有没有办法让我可以get the ciphertext of the values或者怎么go make the code to be runnable in the Rhino JavaScript evaluator.
encryptBase64
的代码是这样的,我不知道how to manage to get the 101 in Kotlin
encryptBase64: function (e) {//e=password
var r = f();
var t = s.default.MD5(r);
console.log("r="+r);//r=GN12MVOFWVZJ51KZ
console.log("t="+t);//r=GN12MVOFWVZJ51KZ
console.log("l="+l);//l=c2df1fd689074ff84521cea43a677bbf
var o = s.default.AES.encrypt(r, l, {iv: l, mode: a, padding: d});
var n = s.default.AES.encrypt(e, t, {iv: t, mode: a, padding: d});
console.log("o="+o)//o=tAzMY2LKjgC96ZJHXYjorazfL56s//vgFgoerDmaH3g=
console.log("n="+n)//n=GQNoFJVGL5qdLyb7KxFXAA==
var o_cipher=o.ciphertext
var n_cipher=n.ciphertext
console.log("o_cipher="+o_cipher)o_cipher=b40ccc6362ca8e00bde992475d88e8adacdf2f9eacfffbe0160a1eac399a1f78
console.log("n_cipher="+n_cipher)//n_cipher=1903681495462f9a9d2f26fb2b115700
var i = s.default.lib.WordArray.create([].concat(c(o_cipher.words), c(n_cipher.words)));
console.log("i="+i)//i=b40ccc6362ca8e00bde992475d88e8adacdf2f9eacfffbe0160a1eac399a1f781903681495462f9a9d2f26fb2b115700
var stringifiedI=s.default.enc.Base64.stringify(i)
console.log("stringified i="+stringifiedI)//stringified i=tAzMY2LKjgC96ZJHXYjorazfL56s//vgFgoerDmaH3gZA2gUlUYvmp0vJvsrEVcA
return stringifiedI
}
我认为ciphertext
可能是像AES,而不是RSA或MD5,因为服务器可以解密它没有密钥(我没有发现任何其他东西,但密码加密).
向学校求助是不可能的,我的学校不批准.
完整的代码如下所示(我想大概是CryptoJS): Full Code in GitHub个
What have I tried
- 我试图用Kotlin编写一些代码来执行类似的功能,但它不能正常工作.
我已经创建了一个AES加密/解密扩展函数,如下所示: aes.kt个
以及包含callJs()
函数的js.kt.
我试着用callJs()
来换取结果.
//fun main
val a= callJs(JS.encryptCode,"aesOene","encryptBase64","password")
println(a)
object JS{
val encryptCode: String by lazy {
val bytes = this::class.java.getResourceAsStream("/aesOene.js")!!.readBytes()
String(bytes)
}
}
我得到了这个
Exception in thread "main" org.mozilla.javascript.EcmaError: ReferenceError: "window" is not defined. (aesOene#1)
我try 用这个来实现encryptBase64()
:
// fun main
val b=encryptBase64("password")
println(b)
fun aesKeyBuilder():String{
val p= arrayListOf("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")
val builder=StringBuilder()
for (t in 0 until 16){
val o= ceil(35*Math.random()).toInt()
builder.append(p[o])
}
return builder.toString()
}
fun encryptBase64(e:String):String{
val r=aesKeyBuilder()
val l="ass-apex".md5
val t=r.md5
val o=r.encryptByAES(l,)
val n=e.encryptByAES(t,)
val i=o+n
return i.base64
}
而且它没有得到正确的结果.
What was I expecting
- 在Kotlin或Java中获得
encryptBase64()
的结果的方法