Reputation: 622
I want to create PEM-encoded certification request but following code
shows error:
PKCS10CRexample.java:33: cannot find symbol
symbol : variable Utils
location: class PKCS10CRexample
kpGen.initialize(1024, Utils.createFixedRandom());
^
1 error
but the code is example from'Beginning Cryptography with Java', thus it should not
include any syntax errors.
what is the problem?, what class should I include?
import java.io.OutputStreamWriter;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.jce.PKCS10CertificationRequest;
import org.bouncycastle.openssl.PEMWriter;
public class PKCS10CRexample
{
public static PKCS10CertificationRequest generateRequest(
KeyPair pair)
throws Exception
{
return new PKCS10CertificationRequest(
"SHA256withRSA",
new X500Principal("CN=Requested Test Certificate"),
pair.getPublic(),
null,
pair.getPrivate());
}
public static void main(String[] args) throws Exception
{
//create the keys
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
kpGen.initialize(1024, Utils.createFixedRandom());
KeyPair pair=kpGen.generateKeyPair();
PKCS10CertificationRequest request = generateRequest(pair);
PEMWriter pemWrt = new PEMWriter(
new OutputStreamWriter(System.out));
pemWrt.writeObject(request);
pemWrt.close();
}
}
Upvotes: 1
Views: 610
Reputation: 5603
The Utils class which implements createFixedRandom()seems to be the one from Chapter 4 of the book.
Have a look at chapter 4 of the book and of the examples of this chapter.
Upvotes: 1