Updated on 2026-08-14
This commit is contained in:
parent
fe16bb4bcf
commit
8d716f97ed
11 changed files with 256 additions and 41 deletions
|
|
@ -0,0 +1,24 @@
|
|||
package com.tangem.common.extensions
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
|
||||
class IntExtensionsTest {
|
||||
|
||||
@Test
|
||||
fun `small int toByteArray`() {
|
||||
val int = 13
|
||||
val expected = byteArrayOf(0, 0, 0, 13)
|
||||
assertThat(int.toByteArray())
|
||||
.isEqualTo(expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `int toByteArray`() {
|
||||
val int = 999
|
||||
val expected = byteArrayOf(0, 0, 3, -25)
|
||||
assertThat(int.toByteArray())
|
||||
.isEqualTo(expected)
|
||||
}
|
||||
}
|
||||
|
|
@ -3,14 +3,8 @@ package com.tangem.common.tlv
|
|||
import com.google.common.truth.Truth.assertThat
|
||||
import com.tangem.common.extensions.calculateSha256
|
||||
import com.tangem.common.extensions.hexToBytes
|
||||
import com.tangem.common.extensions.toHexString
|
||||
import com.tangem.crypto.CryptoUtils
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.SecretKey
|
||||
import javax.crypto.spec.IvParameterSpec
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
|
||||
|
||||
class TlvTest {
|
||||
|
||||
|
|
@ -106,31 +100,4 @@ class TlvTest {
|
|||
assertThat(tlvs1)
|
||||
.isNull()
|
||||
}
|
||||
|
||||
// @Test
|
||||
fun `sldfj dslkf`() {
|
||||
val privateKey = "C9A8827B83D554C2ED6C92A958A75691221A951775C36EBA858C039564ECDC3E"
|
||||
val password = "theXlPiP42".calculateSha256()
|
||||
|
||||
val originalKey: SecretKey = SecretKeySpec(password, 0, password.size, "AES")
|
||||
|
||||
CryptoUtils.initCrypto()
|
||||
|
||||
fun decrypt(yourKey: SecretKey): ByteArray {
|
||||
val decrypted: ByteArray
|
||||
val cipher = Cipher.getInstance("AES", "SC")
|
||||
cipher.init(Cipher.DECRYPT_MODE, yourKey, IvParameterSpec(ByteArray(cipher.blockSize)))
|
||||
decrypted = cipher.doFinal(privateKey.hexToBytes())
|
||||
return decrypted
|
||||
}
|
||||
|
||||
|
||||
val publicKey = CryptoUtils.generatePublicKey(
|
||||
decrypt(originalKey)
|
||||
)
|
||||
|
||||
assertThat(publicKey.toHexString())
|
||||
.isEqualTo("041D020A29983E2BC36E6CEAD9D648A71AA54AD328F00D6336DD699BCEBD99B5F4DAAAAC5E8E6D72D0A94EA86CF0A41D367FE05DE4A1BD84C86D51CCA4AF357182")
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue