Android-Java RSA decrypt

前端 未结 1 1382
孤独总比滥情好
孤独总比滥情好 2021-01-17 02:59

i need to create a public key for RSA algorithm from a binary string.

My code is:

String pubKey = \"tihq/Gk3OUs5NzP+XTRKXBwSxHtB0TWn0RREcpXEtp316tyD9         


        
相关标签:
1条回答
  • 2021-01-17 03:39

    SOLVED. The problem is that i have modulus and exponent and so i must to do this:

    String pubKey = "tihq/Gk3OUs5NzP+XTRKXBwSxHtB0TWn0RREcpXEtp316tyD9DzKaIbdKexb/mRr"; //64 caratteri
    String exponent = "AQAB";
    
    byte[] keyBytes = Base64.decode(pubKey,Base64.DEFAULT);
    byte[] exponentByte = Base64.decode(exponent,Base64.DEFAULT);
    
    KeyFactory keyFactory = KeyFactory.getInstance("RSA");
    
    RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(new BigInteger(keyBytes), new BigInteger(exponentByte));
    RSAPublicKey publicKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec);
    
    0 讨论(0)
提交回复
热议问题