Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a java program to solve the following questions. Submit your code along wi

ID: 3863064 • Letter: W

Question

Write a java program to solve the following questions. Submit your code along with outputs. Let e = n = 12801889219865986943874426789172837719929575398179139903346010225932249438875660672837312104315480979024966347267720662254924720490903440140409487830138442554051215639407252719582615491056895127372123401970340184655821416714383833567438594837829393436445708175846840391647287652219983832401360628720836954408208209 be an RSA public modulus. Note the public key e = n. A Without factoring n, provide a message m together with its RSA sig- nature sigma such that m ends with 2017 in base 10. Show that sigma is a valid signature. B Without factoring n, check that the exponent e' = 9998582802019135990088028686968303570983958400372883846244557704106492590599500521688900757289864181159451333440929176287686491104489407462355371113514648093 is also valid to verify signed messages. Show at least 5 examples.

Explanation / Answer

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.spec.RSAKeyGenParameterSpec;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
public class RSASample {

   public static void main( String args[] ) {

BigInteger modulus = new BigInteger("35087104432820870401058078605540568184774743993337477437336352635278764376464343987348647643");
BigInteger exponent = new BigInteger("545161406957801571786235235735758244123123442");

try {
RSAPublicKeySpec spec = new RSAPublicKeySpec(modulus, exponent);
RSAPrivateKeySpec privateSpec = new RSAPrivateKeySpec(modulus, exponent);

KeyFactory factory = KeyFactory.getInstance("RSA");

PublicKey pub = factory.generatePublic(spec);
PrivateKey priv = factory.generatePrivate(privateSpec);

System.out.println("Public Key : "+ byteArrayToHexString( pub.getEncoded() ));
System.out.println("Private Key : "+ byteArrayToHexString( priv.getEncoded() ));
}
catch( Exception e ) {   
System.out.println(e.toString());   
}
}   
public static String byteArrayToHexString(byte[] bytes)
{   
StringBuffer buffer = new StringBuffer();
for(int i=0; i<bytes.length; i++)
{
if(((int)bytes[i] & 0xff) < 0x10)   
buffer.append("0");   
buffer.append(Long.toString((int) bytes[i] & 0xff, 16));
}
return buffer.toString();
}   
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote