Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I create a RSA key pair so that it can be stored in a database?
    primarykey
    data
    text
    <p>i'm trying to implement a mutating encryption algorithm (theoretically developed by me) and as part of the requirements i need to generate an RSA key pair and store it in the database so that it can be retrieved later as part of the encryption process(only used to encrypt a session key so that it can be sent securely with the encrypted message).</p> <p>my attempt on generating an RSA key pair seem to work however it keeps generating the same values over and over again instead of giving new pairs everytime the code is ran. what did i do wrong? also if those values are dependent on the machine itself (thus displaying the same values) is there a way to link the key pair generation to the email address provided so that every time a new email address is inputted a different RSA key pair will be outputted?</p> <p>the following code is my attempt to generate the key pair:</p> <pre><code>import java.security.*; import java.security.*; /** * @author Speedy gonzales */ public class test { public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchProviderException { KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA"); keyGen.initialize(1024); byte[] publicKey = keyGen.genKeyPair().getPublic().getEncoded(); StringBuffer retString1 = new StringBuffer(); retString1.append("["); for (int puk = 0; puk &lt; publicKey.length; ++puk) { retString1.append(publicKey[puk]); // retString1.append(", "); } retString1 = retString1.delete(retString1.length()-2,retString1.length()); retString1.append("]"); System.out.println(retString1); byte[] privateKey = keyGen.genKeyPair().getPrivate().getEncoded(); StringBuffer retString2 = new StringBuffer(); retString2.append("["); for (int pri = 0; pri &lt; privateKey.length; ++pri) { retString2.append(privateKey[pri]); // retString2.append(", "); } retString2 = retString2.delete(retString2.length()-2,retString2.length()); retString2.append("]"); System.out.println(retString2); } } </code></pre> <p>thanks</p>
    singulars
    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.
 

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