RSA: How to generate private key in java and use it in C#? -
I saved as a 64-base encoded string in a file you want to generate a private key in Java, and then Encrypt some phrases using this saved file, in C # I know how to generate keys in Java and encode it with 64 base. My question is how do I use this key in C #? To save personal file text file Java code prototype: I C # would like to introduce the following function, but the private key can not find a way to make RSAParameters or RSACryptoServiceProvider
KeyPair generator keyGen = KeyPairGenerator.getInstance ( "RSA"); RSakeyGenParameterSpec spec = New RSakeyGenParameterSpec (1024, RSakeyGenParameterSpec.F4); KeyGen.initialize (idea); Keypair keypair = keyGen.generateKeyPair (); Private Private Key = keyPair.getPrivate (); WriteToFile ("Personal", base 64. encode (keyPair.getPrivate). GetEncoded ()));
public static string DecryptData (string privateKey64Base, string data64Base) [making {using // using privateKey64Base // // byte RSAParameters up RSACryptoServiceProvider RSA] encryptedData = rsa.Encrypt (Convert.FromBase64String (data64Base);}
< / Pre>
Advice for your situation, since you are out of 8 (With Unjion writing PKCS # (keyPair.getPrivate ()). GetEncoded) include
This approach would be to get the private key in PRIVATEKEYBLOB format in the first place to use the utility side Java to use.
Alternatively, you can use decode BouncyCastle C # first of Org.BouncyCastle.Security.PrivateKeyFactory.CreateKey - Base64 course (see for example the read key You want to have it)
This past question is. As a result, to change the RSACryptoServiceProvider from the BC key object, answer:
Thirdly, you want to use a major star, e.g. PKCS # 12, which is a more standard (and safe) way to store private keys.
Comments
Post a Comment