RSA - yamase0394/memo GitHub Wiki
Kotlin
//ๅ
ฌ้้ตใๅไฟก
val modulus = BigInteger(1, Base64.decode(base64Modulus, Base64.NO_WRAP))
val exponent = BigInteger(1, Base64.decode(base64Exponent, Base64.NO_WRAP))
//้ตใ็ๆ
val pubKeySpec = RSAPublicKeySpec(modulus, exponent)
val keyFactory = KeyFactory.getInstance("RSA")
val pubKey = keyFactory.generatePublic(pubKeySpec)
val cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding")
cipher.init(Cipher.ENCRYPT_MODE, pubKey)
//ๆๅทๅใใฆ้ไฟก
val encrypted = cipher.doFinal(byteArray)
C#
//ๅ
ฌ้้ตใ็งๅฏ้ตใฎใใขใ็ๆ
var rsa = new RSACryptoServiceProvider(2048);
//ๅ
ฌ้้ตใXMLใซใจใฏในใใผใ
var xml = new XmlDocument();
xml.LoadXml(rsa.ToXmlString(false));
//้ไฟก
var base64Modulus = xml.GetElementsByTagName("Modulus")[0].InnerText;
var base64Exponent = xml.GetElementsByTagName("Exponent")[0].InnerText;
//่งฃ่ชญ
var plain = rsa.Decrypt(encrypted, false);