internal static string Create(GetRsaKeyResponse getRsaKeyResponse, string password) { var encryptPasswordModel = new EncryptPasswordModel { PublicKeyExp = getRsaKeyResponse.PublicKeyExp, PublicKeyMod = getRsaKeyResponse.PublicKeyMod, Password = password }; var encrypted = string.Empty; while (encrypted.Length < 2 || encrypted.Substring(encrypted.Length - 2) != "==") { encrypted = EncryptPassword(encryptPasswordModel); } return(encrypted); }
private static string EncryptPassword(EncryptPasswordModel encryptPasswordModel) { // Convert the public keys to BigIntegers var modulus = CreateBigInteger(encryptPasswordModel.PublicKeyMod); var exponent = CreateBigInteger(encryptPasswordModel.PublicKeyExp); // Original: $data = this.pkcs1pad2($data,($pubkey.modulus.bitLength()+7)>>3); // I'm going to hardcode the bitlength, I can't figure that out right now. var encryptedNumber = Pkcs1Pad2(encryptPasswordModel.Password, (2048 + 7) >> 3); // And now, the RSA encryption encryptedNumber = BigInteger.ModPow(encryptedNumber, exponent, modulus); // Finally we convert the encrypted string back to Base16 var encryptedString = encryptedNumber.ToString("x"); // And then we decode it back // And we put it back into Base64 encryptedString = EncodeBase64(DecodeHex(encryptedString)); return(encryptedString); }