Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>the pkcs1pad2 function converted from javascript to java:</p> <pre><code>public BigInteger pkcs1pad2(String data,int keysize){ byte[] buffer=new byte[keysize]; Random rg=new Random(); if(keysize &lt; data.length()+11) return null; int i = data.length() - 1; while(i &gt;= 0 &amp;&amp; keysize &gt; 0){ --keysize; buffer[keysize] = (byte) data.charAt(i); i--; } --keysize; buffer[keysize] = 0; while(keysize &gt; 2){ --keysize; buffer[keysize] = (byte) (rg.nextInt(254)+1); } --keysize; buffer[keysize] = 2; --keysize; buffer[keysize] = 0; return new BigInteger(buffer); } </code></pre> <p>the rsa encription:</p> <p><a href="http://hc.apache.org/downloads.cgi" rel="nofollow">http://hc.apache.org/downloads.cgi</a></p> <pre><code>//you need httpcomponents-client-4.3.1-bin.zip from apache.org //this contains working Base64 encoder! import org.apache.commons.codec.binary.Base64; public String encrypt(String data,String modulus,String exponent) throws UnsupportedEncodingException{ byte[] exp=Helper.hexToBytes(exponent.toCharArray()); byte[] mod=Helper.hexToBytes(modulus.toCharArray()); BigInteger expB=new BigInteger(exp); BigInteger modB=new BigInteger(mod); BigInteger data2=this.pkcs1pad2(data, (modB.bitLength()+7)&gt;&gt;3); BigInteger data3=data2.modPow(expB, modB); byte[] encoding = (new Base64()).encode(Helper.hexToBytes(data3.toString(16).toCharArray())); return new String(encoding, "US-ASCII"); } </code></pre> <p>and the Helper.HexToBytes:</p> <pre><code> public static byte[] hexToBytes(char[] hex)throws IllegalArgumentException{ byte[] data = new byte[hex.length / 2]; for (int i = 0, j = 0; j &lt; data.length; ++j){ int hi = Character.digit(hex[i++], 16); int lo = Character.digit(hex[i++], 16); if ((hi &lt; 0) || (lo &lt; 0)) throw new IllegalArgumentException(); data[j] = (byte) (hi &lt;&lt; 4 | lo); } return data; } </code></pre>
    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