Created
August 5, 2023 03:13
-
-
Save ultraviolet-jordan/c214e49090060cbc044d61b19f2eb05d to your computer and use it in GitHub Desktop.
This file contains 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 ByteBuffer.rsadec(exponent: BigInteger, modulus: BigInteger) { | |
val length = g1 | |
val dec = BigInteger(gdata(length)).modPow(exponent, modulus).toByteArray() | |
position(0) | |
pdata(dec) | |
position(0) | |
} | |
====================================================================== | |
fun ByteBuffer.rsadec(pem: RSAPrivateCrtKey) { | |
val p = pem.primeP | |
val q = pem.primeQ | |
val dP = pem.primeExponentP | |
val dQ = pem.primeExponentQ | |
val qInv = pem.crtCoefficient | |
val length = g1 | |
val bytes = gdata(length) | |
val data = BigInteger(1, bytes) | |
val m1 = data.mod(p).modPow(dP, p) | |
val m2 = data.mod(q).modPow(dQ, q) | |
val h = qInv * (m1 - m2) % p | |
val dec = (m2 + h * q).toByteArray() | |
position(0) | |
pdata(dec) | |
position(0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment