1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-12-22 16:47:13 +00:00

start implement passport

This commit is contained in:
InsanusMokrassar 2020-06-25 15:45:15 +06:00
parent acfb7066d2
commit d76c09ffb2
7 changed files with 64 additions and 0 deletions

View File

@ -264,6 +264,10 @@ const val permissionsField = "permissions"
const val typeField = "type"
const val valueField = "value"
const val dataField = "data"
const val hashField = "hash"
const val secretField = "secret"
const val pointField = "point"
const val xShiftField = "x_shift"
const val yShiftField = "y_shift"

View File

@ -0,0 +1,5 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.passport.credentials
data class Credentials(
)

View File

@ -0,0 +1,6 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.passport.credentials.common
data class FileCredentials(
val fileHash: String,
val secret: String
)

View File

@ -0,0 +1,15 @@
package com.github.insanusmokrassar.TelegramBotAPI.types.passport.raw
import com.github.insanusmokrassar.TelegramBotAPI.types.*
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
@Serializable
data class EncryptedCredentials(
@SerialName(dataField)
val data: String,
@SerialName(hashField)
val hash: String,
@SerialName(secretField)
val secret: String
)

View File

@ -0,0 +1,11 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils.crypto
import com.soywiz.krypto.AES
import com.soywiz.krypto.Padding
fun decryptSecret(
privateKey: ByteArray,
encryptedSecret: ByteArray
): ByteArray {
AES.decryptAes128Cbc(privateKey, Padding.PKCS7Padding)
}

View File

@ -0,0 +1,20 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils.crypto
import com.soywiz.krypto.AES
import com.soywiz.krypto.Padding
typealias Decryptor = (ByteArray) -> ByteArray
fun createDecryptor(
secret: ByteArray,
hash: ByteArray
): Decryptor {
val secretHash = sha512(secret + hash)
val key = secretHash.copyOfRange(0, 32)
val iv = secretHash.copyOfRange(32, 48)
return {
val decrypted = AES.decryptAesCbc(it, key, iv, Padding.NoPadding)
decrypted.copyOfRange(decrypted[0].toInt(), decrypted.size)
}
}

View File

@ -0,0 +1,3 @@
package com.github.insanusmokrassar.TelegramBotAPI.utils.crypto
external fun sha512(from: ByteArray): ByteArray