Android在应用内结算收据的核查点网(C#) [英] Android in-app billing Verification of Receipt in Dot Net(C#)

查看:184
本文介绍了Android在应用内结算收据的核查点网(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序,它提供应用内结算,我们有我们到的Andr​​oid应用程序连接到我们要推收据到服务器进行验证过程给用户提供服务,在应用程序内购买的应用程序服务器。

I have a Android application which provides in-app billing and we have our application server to which android application connects to provide services to the user, on in-app purchase we want to push receipt to the server for verification process.

现在的问题是,我不知道如何转换安全作为我们的服务器是用点网点网(C#)的.java文件

Now problem is I don't know how to convert Security.java file in dot net(C#) as our server is written in dot net

注:此文件自带的Andr​​oid的应用内计费同一个应用程序,它提供邮件签名功能,我只需要自己的等值点网。

NOTE: This file comes with android in-app billing same application which provides message signing functions i just need their equivalent in dot net.

有关此问题的更多详细信息,请访问 <一href="http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/66bb5683-fde6-47ca-92d7-de255cc8655a" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/66bb5683-fde6-47ca-92d7-de255cc8655a

More Detail regarding this problem is available at http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/66bb5683-fde6-47ca-92d7-de255cc8655a

推荐答案

我找到了解决方案,来实现你首先要对公共密钥格式转换为点网使用排序的不同的密钥作为输入。

I found the solution, to achieve you first have to convert the public key format as dot net uses sort of different Key as an input.

我不知道其他的方式,但我们可以使用Java code,你必须只运行一次,生成点网友好的RSA公钥得到点网格式键。 (这只是建议在给定的市民不迅速例如当Android的市场应用内结算的变化)

I don't know the other ways but we can get dot net format key using a java Code which you have to run only once to generate the dot net friendly RSA Public Key. (this is only recommended when the given public do not changes rapidly e.g. in case of Android market in-app billing)

下面的Java code为我工作。

following Java Code worked for me

public static DotNetRSA GenerateDotNetKey(String base64PubKey)
            throws IOException, NoSuchAlgorithmException,
            InvalidKeySpecException {
        /*
         * String base64PubKey - 
         * Is a Key retrieved from Google Checkout Merchant Account
         */
        BASE64Decoder decoder = new BASE64Decoder();

        byte[] publicKeyBytes = decoder.decodeBuffer(base64PubKey);

        EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(publicKeyBytes);
        RSAPublicKey publicKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(publicKeySpec);

        byte[] modulusBytes = publicKey.getModulus().toByteArray();
        byte[] exponentBytes = publicKey.getPublicExponent().toByteArray();

        modulusBytes = stripLeadingZeros(modulusBytes);

        BASE64Encoder encoder = new BASE64Encoder();
        String modulusB64 = encoder.encode(modulusBytes);
        String exponentB64 = encoder.encode(exponentBytes);

        return new DotNetRSA(modulusB64, exponentB64);
    }

      private static byte[] stripLeadingZeros(byte[] a) {
        int lastZero = -1;
        for (int i = 0; i < a.length; i++) {
          if (a[i] == 0) {
            lastZero = i;
          }
          else {
            break;
          }
        }
        lastZero++;
        byte[] result = new byte[a.length - lastZero];
        System.arraycopy(a, lastZero, result, 0, result.length);
        return result;
      }

现在来验证数字签名,你可以使用下面的code在点网程序(C#)提供GCHO_PUB_KEY_EXP是你的指数和GCHO_PUB_KEY_MOD是你的模数由上面的Java code提取

Now to verify the Digital Signature you can use the following code in your dot net program(c#) provided GCHO_PUB_KEY_EXP is your Exponent and GCHO_PUB_KEY_MOD is your Modulus extracted by above Java Code

public static bool VerifyDataSingature(string data, string sign)
{
     using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
     {
         RSAParameters rsaKeyInfo = new RSAParameters() 
         { 
             Exponent = Convert.FromBase64String(GCHO_PUB_KEY_EXP), 
             Modulus = Convert.FromBase64String(GCHO_PUB_KEY_MOD) 
         };
         rsa.ImportParameters(rsaKeyInfo);

         return rsa.VerifyData(Encoding.ASCII.GetBytes(data), 
                               "SHA1", 
                               Convert.FromBase64String(sign));
     }
}

我希望的工作对我来说这将适用于每个人。谢谢

I hope it will work for everyone as worked for me. Thanks

幸得 code项目ARTICAL

这篇关于Android在应用内结算收据的核查点网(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆