Skip to content

Commit

Permalink
Remove unnecessary BouncyCastle (and remove multidex)
Browse files Browse the repository at this point in the history
  • Loading branch information
lhwdev committed Oct 26, 2020
1 parent 21018a0 commit 3aee6b2
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 16 deletions.
2 changes: 0 additions & 2 deletions api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ plugins {
}

dependencies {
implementation "org.bouncycastle:bcpkix-jdk15to18:1.66"

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-core:1.0.0"
Expand Down
11 changes: 1 addition & 10 deletions api/src/main/kotlin/com/lhwdev/selfTestMacro/api/findUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import org.bouncycastle.jce.provider.BouncyCastleProvider
import java.io.IOException
import java.math.BigInteger
import java.security.KeyFactory
import java.security.Security
import java.security.spec.RSAPublicKeySpec
import javax.crypto.Cipher

Expand Down Expand Up @@ -68,17 +66,10 @@ suspend fun findUser(schoolInfo: SchoolInfo, request: GetUserTokenRequestBody) =

lateinit var encodeBase64: (ByteArray) -> String

private val sProvider = run {
Security.removeProvider("BC")
val provider = BouncyCastleProvider()
Security.addProvider(provider)
provider
}


suspend fun encrypt(string: String): String = ioTask {
val key = RSAPublicKeySpec(BigInteger("30718937712611605689191751047964347711554702318809238360089112453166217803395521606458190795722565177328746277011809492198037993902927400109154434682159584719442248913593972742086295960255192532052628569970645316811605886842040898815578676961759671712587342568414746446165948582657737331468733813122567503321355924190641302039446055143553127897636698729043365414410208454947672037202818029336707554263659582522814775377559532575089915217472518288660143323212695978110773753720635850393399040827859210693969622113812618481428838504301698541638186158736040620420633114291426890790215359085924554848097772407366395041461"), BigInteger("65537"))
val cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding", sProvider)
val cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding")
cipher.init(Cipher.PUBLIC_KEY, KeyFactory.getInstance("RSA").generatePublic(key))
encodeBase64(cipher.doFinal(string.toByteArray()))
}
2 changes: 0 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ android {
dependencies {
implementation project(":api")

implementation "androidx.multidex:multidex:2.0.1"

implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9"
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/lhwdev/selfTestMacro/MainApplication.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.lhwdev.selfTestMacro

import androidx.multidex.MultiDexApplication
import android.app.Application


@Suppress("unused")
class MainApplication : MultiDexApplication() {
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
sDummyForInitialization
Expand Down

0 comments on commit 3aee6b2

Please sign in to comment.