问题描述
publicclassRSAHelper{privatestaticPublicKeya(StringparamString1,StringparamString2){try{paramString2=newX509EncodedKeySpec(Base64.decode(paramString2,2));paramString1=KeyFactory.getInstance(paramString1).generatePublic(paramString2);returnparamString1;}catch(ExceptionparamString1){}returnnull;}publicstaticStringencrypt(StringparamString1,StringparamString2){ObjectlocalObject=null;if("".equals(paramString1)){paramString2="";}for(;;){returnparamString2;try{PublicKeylocalPublicKey=a("RSA",paramString2);paramString2=localObject;if(localPublicKey!=null){paramString2=Cipher.getInstance("RSA/ECB/PKCS1Padding");paramString2.init(1,localPublicKey);paramString1=newString(Base64.encode(paramString2.doFinal(paramString1.getBytes("UTF-8")),2));returnparamString1;}}catch(ExceptionparamString1){}}returnnull;}}
解决方案
解决方案二:
for(;;){returnparamString2;
这种你都好意思拿的出手?你反编译也请先整理下好不?
解决方案三:
看不懂的话您可以不说话的
解决方案四:
这个都不需要转,直接可以用,啥事都没做,直接出来了for(;;){returnparamString2;
解决方案五:
不知道为什么反编译出来的源码会这样,但是我用IDEA调试,并没有直接返回,而是走到了下面的语句加密了传入密码paramString2=Cipher.getInstance("RSA/ECB/PKCS1Padding");paramString2.init(1,localPublicKey);paramString1=newString(Base64.encode(paramString2.doFinal(paramString1.getBytes("UTF-8")),2));returnparamString1;
我使用C#写了这个过程投递过去都是失败的...,这个公钥虽然每次都是动态获取的但是并没有变,所以我就固定了varkeyBytes=Convert.FromBase64String("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDZ6i9VNEGEaZaYE7XffA9XRj15cp/ZKhHYY43EEva8LIhCWi29EREaF4JjZVMwFpUAfrL+9gpA7NMQmaMRHbrz1KHe2Ho4HpUhEac8M9zUbNvaDKSlhx0lq/15TQP+57oQbfJ9oKKd+he4Yd6jpBI3UtGmwJyN/T1S0DQ0aXR8OQIDAQAB");//yourkeyhereAsymmetricKeyParameterasymmetricKeyParameter=PublicKeyFactory.CreateKey(keyBytes);RsaKeyParametersrsaKeyParameters=(RsaKeyParameters)asymmetricKeyParameter;RSAParametersrsaParameters=newRSAParameters();rsaParameters.Modulus=rsaKeyParameters.Modulus.ToByteArrayUnsigned();rsaParameters.Exponent=rsaKeyParameters.Exponent.ToByteArrayUnsigned();RSACryptoServiceProviderrsa=newRSACryptoServiceProvider();rsa.ImportParameters(rsaParameters);byte[]plaintext=Encoding.UTF8.GetBytes("a888888");byte[]ciphertext=rsa.Encrypt(plaintext,false);stringcipherresult=Convert.ToBase64String(ciphertext);Console.WriteLine(cipherresult);Console.Read();