Kotlin Encryption

Kotlin Encryption

Kotlin is now the default language for new Android work and sits comfortably on the JVM next to Java for servers and tools. It cuts boilerplate, plays nicely with existing Java libraries, and also targets JavaScript and native via Kotlin Multiplatform. If you ship a mobile app or a Spring service, you have probably touched it already.

APKs and server JARs still leak strings to anyone with a decompiler; backend URLs, analytics tokens, and feature flags are obvious targets. StringEncrypt outputs Kotlin you can paste in so those values decrypt at runtime instead of living as plain source. It will not replace a remote config service, but it beats leaving secrets in cleartext next to your UI code.

String encryption supports both UNICODE and ANSI strings.

Official resources:

Kotlin Encryption (UNICODE Example)

Plaintext reference: StringEncrypt sample

// encrypted with https://www.stringencrypt.com (v1.5.0) [Kotlin]
// myString = "StringEncrypt sample"
var myString: String = ""

val lnJPS: IntArray = intArrayOf( 0x0C4E, 0x6966, 0x150D, 0x8FC6, 0x1818, 0x12A8, 0x7711, 0xD626,
                                  0x242E, 0xBAE6, 0x1715, 0x1EE7, 0x300C, 0x0221, 0x2B19, 0x68C7,
                                  0x3C1A, 0x0A67, 0x411D, 0xAF47 )

var QJwRB: Int = 0
for (sJMTI in 0 until 20)
{
	QJwRB = lnJPS[sJMTI]
	QJwRB = (((QJwRB and 0xFFFF) shr 8) or ((QJwRB and 0xFFFF) shl 8)) and 0xFFFF
	QJwRB = ((QJwRB and 0xFFFF) - 0xA9F5) and 0xFFFF
	QJwRB = ((QJwRB and 0xFFFF) + 0x54CB) and 0xFFFF
	QJwRB = ((QJwRB and 0xFFFF) - sJMTI) and 0xFFFF
	QJwRB = ((QJwRB and 0xFFFF) + 0xCF49) and 0xFFFF
	QJwRB = ((QJwRB and 0xFFFF) - sJMTI) and 0xFFFF
	QJwRB = ((QJwRB and 0xFFFF) - 0x19C0) and 0xFFFF
	for (MUaXL in 0 until 2)
	{
		for (jYsQI in 0 until 2)
		{
			for (vnPxa in 0 until 2)
			{
				QJwRB = (QJwRB xor 0xFFFF) and 0xFFFF
			}
			QJwRB = (((QJwRB and 0xFFFF) shl (sJMTI % 16)) or ((QJwRB and 0xFFFF) shr (16 - (sJMTI % 16)))) and 0xFFFF
		}
	}
	QJwRB = ((QJwRB and 0xFFFF) - sJMTI) and 0xFFFF
	QJwRB = ((QJwRB and 0xFFFF) + 1) and 0xFFFF
	QJwRB = (((QJwRB and 0xFFFF) xor 0xFFFF) + 1) and 0xFFFF
	for (YxTfK in 0 until 2)
	{
		QJwRB = ((QJwRB and 0xFFFF) - 1) and 0xFFFF
	}
	for (Yunef in 0 until 2)
	{
		QJwRB = ((QJwRB and 0xFFFF) + 0x20EA) and 0xFFFF
	}
	QJwRB = (((QJwRB and 0xFFFF) shl 7) or ((QJwRB and 0xFFFF) shr 9)) and 0xFFFF
	QJwRB = ((QJwRB and 0xFFFF) + 0x4D0A) and 0xFFFF
	myString += (QJwRB and 0xFFFF).toChar()
}

Kotlin Encryption (ANSI Example)

Plaintext reference: StringEncrypt sample

// encrypted with https://www.stringencrypt.com (v1.5.0) [Kotlin]
// myString = "StringEncrypt sample"
var myString: String = ""

val ZEauM: IntArray = intArrayOf( 0xD2, 0x72, 0x1E, 0x21, 0x5F, 0xB2, 0x71, 0x06,
                                  0x2D, 0x02, 0x8E, 0x33, 0x56, 0xE8, 0xAB, 0xAC,
                                  0x85, 0x8B, 0xFC, 0x42 )

var toOQS: Int = 0
for (fdzSy in 0 until 20)
{
	toOQS = ZEauM[fdzSy]
	toOQS = (toOQS xor 0xFF) and 0xFF
	for (iEpmJ in 0 until 2)
	{
		for (noBlQ in 0 until 4)
		{
			toOQS = (toOQS xor fdzSy) and 0xFF
		}
	}
	for (Bzevx in 0 until 2)
	{
		toOQS = ((toOQS and 0xFF) + fdzSy) and 0xFF
		for (leUms in 0 until 2)
		{
			toOQS = (((toOQS and 0xFF) shl (fdzSy % 8)) or ((toOQS and 0xFF) shr (8 - (fdzSy % 8)))) and 0xFF
			for (IYowT in 0 until 2)
			{
				toOQS = (toOQS xor 0x2E) and 0xFF
			}
			for (qwtSM in 0 until 3)
			{
				toOQS = ((toOQS and 0xFF) - 0x05) and 0xFF
				toOQS = ((toOQS and 0xFF) - 1) and 0xFF
				toOQS = ((toOQS and 0xFF) - 0x74) and 0xFF
			}
		}
	}
	toOQS = (toOQS xor fdzSy) and 0xFF
	toOQS = ((toOQS and 0xFF) + fdzSy) and 0xFF
	for (NcivP in 0 until 2)
	{
		toOQS = ((toOQS and 0xFF) + 1) and 0xFF
		for (JmdpK in 0 until 4)
		{
			toOQS = ((toOQS and 0xFF) + 0xD8) and 0xFF
			toOQS = (toOQS xor fdzSy) and 0xFF
		}
	}
	toOQS = ((toOQS and 0xFF) + fdzSy) and 0xFF
	toOQS = (((toOQS and 0xFF) shr 4) or ((toOQS and 0xFF) shl 4)) and 0xFF
	toOQS = (toOQS xor 0x20) and 0xFF
	myString += (toOQS and 0xFF).toChar()
}