未知格式的 RSA 加密
RSA Encryption with unknown format
这种加密格式可以实现什么?
我的 android 应用程序将加密消息发送到 c# 服务器,但服务器实际上想要加密消息,就像这种未知格式chinese words
。
[![未知加密格式][1]][1]
但是android 加密消息像这样的格式 (on7vQhgNeVDVDu4evL0HZ5UbC2C1oZdamfU9XBLGZQZ13MLQKu2speIWNaldsfcGfPS
)
我使用 C sharp 和 android 中具有相同 public/private 密钥的 RSA 算法。
我在哪里被打扰了?
这种未知格式的方法有问题。
似乎 android 加密 class 有问题我不知道这个问题还需要使用什么
谢谢指教
Android代码
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acti);
try {
generateKey();
} catch (Exception e1) {
e1.printStackTrace();
}
}
public static void generateKey() throws Exception {
String modulusString = "tx94IV9NAutFU1HQjXmkLzknJ5vatOFyhD90Un3u5oiOc4e9fT1bsM0af3OqNMCTRLPuQJ2JQokY+3T0icJqHgG/aHvbmvDvRKn2QrVxAFt8EN6jp/S6+dRe1B/6eJbVRJJpeekLslqGqdQgr+5ocD+ZPjiE2iL6sGGyAYz+lOJtSr9N4ZcD4kNikI3J9kZDNO78rEqQuX7flh0RS79N63MJ9xX9fBuqHFIud3KKKbqHiASQoaU1rWqZ2VIdqfXzreZMYHpHYioVzyrbk/wdQQV2ibmJFAsa5aiKSP+g9rF4xYoPAistePDwn4O+wARGlMsu7RYVAIeUM77l+w6ugw==";
String ExponentString = "AQAB";
byte[] modulusBytes = Base64.decode(modulusString.getBytes("UTF-8"), Base64.DEFAULT);
byte[] exponentBytes = Base64.decode(ExponentString.getBytes("UTF-8"),Base64.DEFAULT);
BigInteger modulus = new BigInteger(1, modulusBytes);
BigInteger publicExponent = new BigInteger(1, exponentBytes);
KeyFactory fact = KeyFactory.getInstance("RSA");
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING");
String INPUT = "GAVDOOL";
RSAPublicKeySpec rsaPubKey = new RSAPublicKeySpec(modulus, publicExponent);
PublicKey pubKey = fact.generatePublic(rsaPubKey);
cipher.init(Cipher.ENCRYPT_MODE, pubKey);
// byte[] plainBytes = clearTextPassword.getBytes();
byte[] cipherData = cipher.doFinal(INPUT.getBytes());
String encryptedStringBase64 = Base64.encodeToString(cipherData, Base64.DEFAULT);
System.out.println("Encrypted?????"+encryptedStringBase64);
System.out.println(encryptedStringBase64.length());
}
}
未知的加密格式,请参阅 [1]:http://i.stack.imgur.com/hF84B.jpg
从未调用方法 encrypt(data)?似乎您有一些无法访问的代码...
已解决,
我终于更改了服务器代码并删除了 Encoding.Unicode 部分,现在这个问题消失了。
这种加密格式可以实现什么?
我的 android 应用程序将加密消息发送到 c# 服务器,但服务器实际上想要加密消息,就像这种未知格式chinese words
。
[![未知加密格式][1]][1]
但是android 加密消息像这样的格式 (on7vQhgNeVDVDu4evL0HZ5UbC2C1oZdamfU9XBLGZQZ13MLQKu2speIWNaldsfcGfPS
)
我使用 C sharp 和 android 中具有相同 public/private 密钥的 RSA 算法。 我在哪里被打扰了?
这种未知格式的方法有问题。
似乎 android 加密 class 有问题我不知道这个问题还需要使用什么
谢谢指教
Android代码
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.acti);
try {
generateKey();
} catch (Exception e1) {
e1.printStackTrace();
}
}
public static void generateKey() throws Exception {
String modulusString = "tx94IV9NAutFU1HQjXmkLzknJ5vatOFyhD90Un3u5oiOc4e9fT1bsM0af3OqNMCTRLPuQJ2JQokY+3T0icJqHgG/aHvbmvDvRKn2QrVxAFt8EN6jp/S6+dRe1B/6eJbVRJJpeekLslqGqdQgr+5ocD+ZPjiE2iL6sGGyAYz+lOJtSr9N4ZcD4kNikI3J9kZDNO78rEqQuX7flh0RS79N63MJ9xX9fBuqHFIud3KKKbqHiASQoaU1rWqZ2VIdqfXzreZMYHpHYioVzyrbk/wdQQV2ibmJFAsa5aiKSP+g9rF4xYoPAistePDwn4O+wARGlMsu7RYVAIeUM77l+w6ugw==";
String ExponentString = "AQAB";
byte[] modulusBytes = Base64.decode(modulusString.getBytes("UTF-8"), Base64.DEFAULT);
byte[] exponentBytes = Base64.decode(ExponentString.getBytes("UTF-8"),Base64.DEFAULT);
BigInteger modulus = new BigInteger(1, modulusBytes);
BigInteger publicExponent = new BigInteger(1, exponentBytes);
KeyFactory fact = KeyFactory.getInstance("RSA");
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1PADDING");
String INPUT = "GAVDOOL";
RSAPublicKeySpec rsaPubKey = new RSAPublicKeySpec(modulus, publicExponent);
PublicKey pubKey = fact.generatePublic(rsaPubKey);
cipher.init(Cipher.ENCRYPT_MODE, pubKey);
// byte[] plainBytes = clearTextPassword.getBytes();
byte[] cipherData = cipher.doFinal(INPUT.getBytes());
String encryptedStringBase64 = Base64.encodeToString(cipherData, Base64.DEFAULT);
System.out.println("Encrypted?????"+encryptedStringBase64);
System.out.println(encryptedStringBase64.length());
}
}
未知的加密格式,请参阅 [1]:http://i.stack.imgur.com/hF84B.jpg
从未调用方法 encrypt(data)?似乎您有一些无法访问的代码...
已解决,
我终于更改了服务器代码并删除了 Encoding.Unicode 部分,现在这个问题消失了。