RSA Encryption: Difference between Java and Android

前端 未结 3 656
眼角桃花
眼角桃花 2020-12-04 15:57

I am using RSA to encrypt username and password on Android and decrypt them on server (tomcat 6, java 1.6). Android Encryption:

    PublicKey pubKey = readPu         


        
3条回答
  •  温柔的废话
    2020-12-04 16:30

    Firstly, it looks like you're initializing both ciphers with the public key. Encryption uses public key, decryption used private key. I hope that's just a typo though.

    I had a lot of trouble with RSA encryption as well, much was trial and error. I suggest you try another provider. I managed to implement RSA using BouncyCastle.

    Cipher wrapper = Cipher.getInstance("RSA", "BC");
    wrapper.init(Cipher.ENCRYPT_MODE, publicKey);
    encryptedData= wrapper.doFinal(unencryptedData);
    

    Although, I generated my own keypair since this was a session encryption.

    kpg = KeyPairGenerator.getInstance("RSA");
            kpg.initialize(1024);
            KeyPair kp = kpg.genKeyPair();
            publicKey = kp.getPublic();
            privateKey = kp.getPrivate();
    

提交回复
热议问题