Sunday 15 May 2011

Java and C++ (VS) RSA encryption -


I am trying to talk to 2 applications using RSA to talk to each other first in C ++ and The second one is in Java first need to send a public key in a Java key. I am using a

  CryptExportKey (m_hCryptKey, NULL, PUBLICKEYBLOB, 0, pbKeyBlob, and dwBlobLen); For this, in the Java application I was trying to import it using this function:  
  get public public key publicKeyFromBytes ( Byte [] keybites throws NoSuchAlgorithmException, Invalid KeySpecException {KeyFactory keyFactory; KeyFactory = KeyFactory.getInstance ("RSA"); X509 EncodedKSPEKEPUBESEPEC = New X509 EncodedKSSPEC (Keybites); Return key Factory.generatePublic (pubKeySpec); }   

This invalid keySpecException throws Can you please tell me how am I getting the import / export key?

You must write decoder for the Microsoft RSA public key structure. Fortunately note that this little-endian encoding So that you first wrap the structure in the low-endion in ByteBuffer .

Then you can access public exponent and modulus parts by using the BigInteger and BigInter.ViewOf (1, BigIndianBitArray) . After reading them from ByteBuffer , get the bytes in bigEndianByteArray in the correct order.

No comments:

Post a Comment