java(android) rsa 实现与 php 服务端通信

rsa 密钥生成 见 http://blog.andsky.com/js-rsa-use-openssl-make-public-pirvate-key/ android 客户端用rsa 公钥加密后经 base64 编码发到 服务端,服务端使用私钥解密 客户端代码 import java.math.BigInteger; import java.security.KeyFactory; import java.security.PublicKey; import java.security.spec.RSAPublicKeySpec; import javax.crypto.Cipher; import sun.misc.BASE64Encoder; public class rsa { public static void main(String[] args) throws Exception { String modulus = "C34FF1FF9771ED88814C26905297BAEDCEC03B847D8AB5620848FC100AC0564FAD5364E9834E29118E7B5F8B1B9EAB201730C4860E8AF2ED2E028704105A01044501A9EF6DA2968E76273AAE496A0963A2FEA9B6179A86F28ACC61C087FB1AEEA4E1CB0ADBB9B757C303741DE602FD790953C8E2C004A425C7CAF4813F403DCD"; String publicExponent = "010001"; rsa key = new rsa(); PublicKey publicKey = key.getPublicKey(modulus, publicExponent); Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); //明文 String tString = "aabbsdfsdf"; byte[] plainText = tString.getBytes("UTF-8"); //加密 cipher.init(Cipher.ENCRYPT_MODE, publicKey); byte[] enBytes = cipher....

2013-12-21 · 1 分钟 · admin

js rsa 使用 openssl 生成公钥私钥

生成私钥 openssl genrsa -out key.pem 得到16进制公钥 openssl rsa -in key.pem -noout -modulus 直接放到js里就可以使用了

2013-12-12 · 1 分钟 · admin