mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
start implement passport
This commit is contained in:
parent
acfb7066d2
commit
d76c09ffb2
@ -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"
|
||||
|
@ -0,0 +1,5 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.passport.credentials
|
||||
|
||||
data class Credentials(
|
||||
|
||||
)
|
@ -0,0 +1,6 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.types.passport.credentials.common
|
||||
|
||||
data class FileCredentials(
|
||||
val fileHash: String,
|
||||
val secret: String
|
||||
)
|
@ -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
|
||||
)
|
@ -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)
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
package com.github.insanusmokrassar.TelegramBotAPI.utils.crypto
|
||||
|
||||
external fun sha512(from: ByteArray): ByteArray
|
Loading…
Reference in New Issue
Block a user