public static string RsaEncryptJava(string publicKey, string serct) { var a = Base64.decode(publicKey); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(a); KeyFactory keyFactory = KeyFactory.getInstance("RSA"); RSAPublicKey publicKey1 = (RSAPublicKey)keyFactory.generatePublic(keySpec); Cipher cipher = Cipher.getInstance("RSA"); cipher.init(Cipher.ENCRYPT_MODE, publicKey1); // 模长 int key_len = publicKey1.getModulus().bitLength() / 8; // 加密数据长度 <= 模长-11 string[] datas = splitString(serct, key_len - 11); string mi = ""; //如果明文长度大于模长-11则要分组加密 foreach (string s in datas) { mi += bcd2Str(cipher.doFinal(System.Text.Encoding.UTF8.GetBytes(s))); } return(mi); }
/// <summary> /// Initializes the facade. Should only be called once. /// </summary> /// <param name="context">An Android Context object. Usually the Activity object.</param> /// <param name="developerUuid">The developer UUID, which is obtained from the developer portal.</param> public void Init(Android.Content.Context context, string developerUuid) { // Load the key from the resources byte[] applicationKey = null; var resId = context.Resources.GetIdentifier("key", "raw", context.PackageName); using (var stream = context.Resources.OpenRawResource(resId)) { using (var ms = new MemoryStream()) { stream.CopyTo(ms); applicationKey = ms.ToArray(); } } // Generate the public key from the application key using (var keySpec = new X509EncodedKeySpec(applicationKey)) { using (var keyFactory = KeyFactory.GetInstance("RSA")) { _publicKey = keyFactory.GeneratePublic(keySpec); } } InitInternal(context, developerUuid); OuyaController.Init(context); Log("Hardware: " + GetDeviceHardware().DeviceName()); }
/// <summary> /// Get PublicKey /// </summary> /// <param name="key">key(by Base64)</param> /// <returns></returns> private static IPublicKey GetPublicKey(string key) { X509EncodedKeySpec keySpec = new X509EncodedKeySpec(Base64Hw.Decode(key)); KeyFactory keyFactory = KeyFactory.GetInstance("RSA"); IPublicKey publicKey = keyFactory.GeneratePublic(keySpec); return(publicKey); }
public PublicKey GeneratePublic(X509EncodedKeySpec var1) { throw new System.NotImplementedException(); }