Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8381343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:40:42+00:00 2026-06-09T16:40:42+00:00

i’m trying to implement a mutating encryption algorithm (theoretically developed by me) and as

  • 0

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).

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?

the following code is my attempt to generate the key pair:

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 < 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 < privateKey.length; ++pri) {
            retString2.append(privateKey[pri]);
           // retString2.append(", ");
        }
        retString2 = retString2.delete(retString2.length()-2,retString2.length());
        retString2.append("]");
        System.out.println(retString2); 
    }
}

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:40:43+00:00Added an answer on June 9, 2026 at 4:40 pm

    Well, your first problem is:

    keyGen.genKeyPair().getPublic().getEncoded();
    keyGen.genKeyPair().getPrivate().getEncoded();
    

    You’re not saving the keypair, so you are generating public and private keys that don’t match. From the javadocs, genKeyPair() behaves as follows:

    This will generate a new key pair every time it is called.

    Secondly, getEncoded() just returns the key as a byte array. If your database can store binary values, just store it that way. Otherwise, you would probably have much better luck converting it to a String somehow. You could, for example, base 64 encode it with this neat little trick (probably more reliable that what you’re doing):

    String keyAsString = new BigInteger(publicKey.getEncoded()).toString(64);
    

    You can subsequently get the original bytes back with:

    byte[] bytes = new BigInteger(keyAsString, 64).toByteArray();
    

    You say that you’re getting the same value every run (and make SURE you are before bothering with this), and I’m not 100% sure why. You should be able to access the algorithm parameters (you might have to cast the key to a different type), try printing those to see if they are the same. Someone mentioned checking your random number generator, that might be a good idea too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.