This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typealias CountingRequestListener = (bytesWritten: Long, contentLength: Long) -> Unit | |
| class CountingSink( | |
| sink: Sink, | |
| private val requestBody: RequestBody, | |
| private val onProgressUpdate: CountingRequestListener | |
| ) : ForwardingSink(sink) { | |
| private var bytesWritten = 0L | |
| override fun write(source: Buffer, byteCount: Long) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CountingRequestBody( | |
| private val requestBody: RequestBody, | |
| private val onProgressUpdate: CountingRequestListener | |
| ) : RequestBody() { | |
| override fun contentType() = requestBody.contentType() | |
| @Throws(IOException::class) | |
| override fun contentLength() = requestBody.contentLength() | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun createUploadRequestBody(file: File, mimeType: String) = | |
| file.asRequestBody(mimeType.toMediaType()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Multipart | |
| @POST("file") | |
| fun attachFile( | |
| @Part("name") filename: RequestBody, | |
| @Part("type") mimeType: RequestBody, | |
| @Part("size") fileSize: RequestBody, | |
| @Part filePart: MultipartBody.Part | |
| ): Single<AttachmentUploadedRemoteDto> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun decrypt(encryptedData: ByteArray): String? { | |
| val encryptionKey = generateKey() | |
| val cell = SecureCell(encryptionKey, SecureCell.MODE_SEAL) | |
| return try { | |
| val cellData = SecureCellData(encryptedData, null) | |
| val decodedData = cell.unprotect(encryptionContext, cellData) | |
| String(decodedData) | |
| } catch (error: SecureCellException) { | |
| Log.e("EncryptionEngine", "Failed to decrypt message, error) | |
| null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val encryptedDaya = Base64.decode(secretAsBase64, Base64.NO_WRAP) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val encypted = EncryptionEngine().encrypt("raw_secret_value") | |
| Log.d("ENCRYPTED", encypted.base64EncodedString()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun encrypt(message: String): ByteArray { | |
| val encryptionKey = generateKey() | |
| val cell = SecureCell(encryptionKey, SecureCell.MODE_SEAL) | |
| val protectedData = cell.protect( | |
| encryptionContext, message.toByteArray() | |
| ) | |
| return protectedData.protectedData | |
| } | |
| private val encryptionContext: ByteArray? = null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun generateKey(): ByteArray { | |
| val rawKey = buildString(5) { | |
| append(byteArrayOf(0x12, 0x27, 0x42).base64EncodedString()) | |
| append(500 + 6 / 7 * 89) | |
| append(BuildConfig.ENCRYPTION_KEY) | |
| append("pghy^%£aft") | |
| } | |
| return rawKey.toByteArray() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| GameCatalogueApp_EncryptionKey=super_secret_key | |
| buildConfigField( | |
| "String", | |
| "ENCRYPTION_KEY", | |
| buildConfigProperty("GameCatalogueApp_EncryptionKey") | |
| ) |