请教一下,我最近在做一个项目,关于RSA跨平台加密的问题,想请教一下。
对方是在java下开发的。他在java里使用的公钥是
encryption.exponent=65537
encryption.modulus=99737572601622950594313242995539669866163053332469824383108769945511776708235028686883156035958767022666215057997361167810820326127476888205541371556602858192487521093515406064801586674737304778209665857689637024543746717913961184459249524029418340739860249861312830574212799904443725436908298663804941582811
在jsp里,他的加密语句是
PublicKey publicKey = encrytionUtil.getPublicKey(SystemProperty.getInstance().getPropertyValue("encryption.modulus"), SystemProperty.getInstance().getPropertyValue("encryption.exponent"));
String vendorUniqueKey = encrytionUtil.encrypt(publicKey, “需要加密的字符串”);
我现在需要在.net下实现这个功能。
我的代码是
          RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
          RSAParameters para = new RSAParameters();
          string publicKey = "AQAB";//这里如果用65537编译就不通过。所以找了一些资料。可以把65537改成AQAB.
          string modulus = "99737572601622950594313242995539669866163053332469824383108769945511776708235028686883156035958767022666215057997361167810820326127476888205541371556602858192487521093515406064801586674737304778209665857689637024543746717913961184459249524029418340739860249861312830574212799904443725436908298663804941582811";
  string m = "要加密的字符串";
                para.Exponent = Convert.FromBase64String(publicKey);
                para.Modulus = Convert.FromBase64String(modulus);
                rsa.ImportParameters(para);
                byte[] enBytes = rsa.Encrypt(UTF8Encoding.UTF8.GetBytes(m), false);                return Convert.ToBase64String(enBytes);
==========================================
加密的结果,发送到java服务器去解密就是不通过。
请各位高手指点一下

解决方案 »

  1.   

    java的encrytionUtil.getPublicKey。定义是
    public PublicKey getPublicKey(String mod, String exp) throws Exception {
    PublicKey pubKey = null;
    BigInteger m = new BigInteger(mod);
    BigInteger e = new BigInteger(exp);
    RSAPublicKeySpec keySpec = new RSAPublicKeySpec(m, e);
        KeyFactory fact = KeyFactory.getInstance(ALOG);
        pubKey = fact.generatePublic(keySpec);
       
        return pubKey;
    }