Skip to content

Instantly share code, notes, and snippets.

View EhsanSetayesh's full-sized avatar

Ehsan Setayesh EhsanSetayesh

View GitHub Profile
@EhsanSetayesh
EhsanSetayesh / MultiPart Upload PFX file
Created January 30, 2024 11:10
Create retrofit Multi Part api call to upload cert file
@POST("api/v1/testApp/sign")
@Multipart
suspend fun sign(
@Part certFile: MultipartBody.Part,
@Part passwordFile: MultipartBody.Part,
@Part("data") data: RequestBody
): Response<CustomResponseModel>
private fun readPfxFileFromAssets(context: Context, fileName: String): ByteArray {
import android.security.keystore.KeyGenParameterSpec
import android.security.keystore.KeyProperties
import java.nio.charset.StandardCharsets
import java.security.KeyPairGenerator
import java.security.KeyStore
import java.util.Base64
import javax.crypto.Cipher
const val KEYSTORE_ALIAS = "apiKeys"
const val ANDROID_KEYSTORE = "AndroidKeyStore"
const val PREF_NAME = "apiKeys"
const val PREF_DATA = "PREF_DATA"
class EncryptedPreferencesImpl(context: Context) : EncryptedPreferences {
private val masterKey = MasterKey.Builder(context)
.setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
.build() as? MasterKey
private val preferences = masterKey?.let {
EncryptedSharedPreferences.create(