Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks to GregS answers I found solution of my problem. Now I post this.</p> <p><strong>C# SIDE</strong> (Client-Side)</p> <pre><code>X509Certificate2 x509 = new X509Certificate2(); byte[] rawData = ReadFile("mycert.cer"); x509.Import(rawData); </code></pre> <p>After I loads my X509Certificate I call my execute method:</p> <pre><code>public static String execute(String content) { ASCIIEncoding encoding = new ASCIIEncoding(); byte[] plainbytes = System.Text.Encoding.ASCII.GetBytes(content); byte[] cipherbytes = rsa.Encrypt(plainbytes, false); SoapHexBinary hexBinary = new SoapHexBinary(cipherbytes); String cipherHex = hexBinary.ToString(); // This String is used on java side to decrypt Console.WriteLine("CIPHER HEX: " + cipherHex); return cipherHex; } </code></pre> <p><strong>JAVA SIDE</strong> (Server-Side)</p> <pre><code>keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); keyStore.load(new FileInputStream("C:\\my.keystore"), "mypass".toCharArray()); Key key = keyStore.getKey("myalias", "mypass".toCharArray()); if (key instanceof PrivateKey) { Certificate cert = keyStore.getCertificate("myalias"); PublicKey pubKey = cert.getPublicKey(); privKey = (PrivateKey)key; } byte[] toDecodeBytes = new BigInteger(encodeMessageHex, 16).toByteArray(); Cipher decCipher = Cipher.getInstance("RSA/ECB/PKCS1Padding"); decCipher.init(Cipher.DECRYPT_MODE, privKey); byte[] decodeMessageBytes = decCipher.doFinal(toDecodeBytes); String decodeMessageString = new String(decodeMessageBytes); </code></pre> <p>The problem was in Hex-Encryption on C# Side that are completely different on Java side. Thanks GregS, you are the best ;)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload