Add DSA support to tests and a few more signing algorithms
import org.bouncycastle.asn1.DERNull;
import org.bouncycastle.asn1.DERSequence;
import org.bouncycastle.asn1.cryptopro.CryptoProObjectIdentifiers;
+import org.bouncycastle.asn1.nist.NISTObjectIdentifiers;
+import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
static
{
algIds.put("GOST3411withGOST3410", new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94));
+ algIds.put("SHA1withDSA", new AlgorithmIdentifier(OIWObjectIdentifiers.dsaWithSHA1, DERNull.INSTANCE));
+ algIds.put("SHA224withDSA", new AlgorithmIdentifier(NISTObjectIdentifiers.dsa_with_sha224, DERNull.INSTANCE));
+ algIds.put("SHA256withDSA", new AlgorithmIdentifier(NISTObjectIdentifiers.dsa_with_sha256, DERNull.INSTANCE));
algIds.put("SHA1withRSA", new AlgorithmIdentifier(PKCSObjectIdentifiers.sha1WithRSAEncryption, DERNull.INSTANCE));
+ algIds.put("SHA224withRSA", new AlgorithmIdentifier(PKCSObjectIdentifiers.sha224WithRSAEncryption, DERNull.INSTANCE));
algIds.put("SHA256withRSA", new AlgorithmIdentifier(PKCSObjectIdentifiers.sha256WithRSAEncryption, DERNull.INSTANCE));
+ algIds.put("SHA1withECDSA", new AlgorithmIdentifier(X9ObjectIdentifiers.ecdsa_with_SHA1));
+ algIds.put("SHA224withECDSA", new AlgorithmIdentifier(X9ObjectIdentifiers.ecdsa_with_SHA224));
algIds.put("SHA256withECDSA", new AlgorithmIdentifier(X9ObjectIdentifiers.ecdsa_with_SHA256));
}
@@ -149,6 +157,19 @@ public static X509Certificate createCert(X500Name signerName, PrivateKey signerK
.generateCertificate(new ByteArrayInputStream(new DERSequence(v).getEncoded(ASN1Encoding.DER)));
}
+ /**
+ * Create a random 1024 bit DSA key pair
+ */
+ public static KeyPair generateDSAKeyPair()
+ throws Exception
+ {
+ KeyPairGenerator kpGen = KeyPairGenerator.getInstance("DSA", BouncyCastleProvider.PROVIDER_NAME);
+
+ kpGen.initialize(1024, new SecureRandom());
+
+ return kpGen.generateKeyPair();
+ }
+
/**
* Create a random 1024 bit RSA key pair
*/
@@ -175,7 +196,12 @@ public static KeyPair generateECKeyPair()
public static X509Certificate generateRootCert(KeyPair pair)
throws Exception
{
- if (pair.getPublic().getAlgorithm().equals("RSA"))
+ String alg = pair.getPublic().getAlgorithm();
+ if (alg.equals("DSA"))
+ {
+ return createSelfSignedCert("CN=Test CA Certificate", "SHA1withDSA", pair);
+ }
+ else if (alg.equals("RSA"))
{
return createSelfSignedCert("CN=Test CA Certificate", "SHA256withRSA", pair);
}
