repo
stringlengths 1
191
⌀ | file
stringlengths 23
351
| code
stringlengths 0
5.32M
| file_length
int64 0
5.32M
| avg_line_length
float64 0
2.9k
| max_line_length
int64 0
288k
| extension_type
stringclasses 1
value |
|---|---|---|---|---|---|---|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/secureConfigsRSA/src/main/java/example/SecureConfig128bitsRSA_3072x384_2.java
|
package example;
import javax.crypto.*;
import java.security.*;
import org.bouncycastle.jce.provider.*;
public final class SecureConfig128bitsRSA_3072x384_2 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 3072;
int hsize = 384;
int maxLenBytes = (ksize - 2 * hsize) / 8 - 2;
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(ksize);
KeyPair kp = kpg.generateKeyPair();
Cipher c = Cipher.getInstance("RSA/None/OAEPwithSHA384andMGF1Padding", "BC");
Key pubk = kp.getPublic();
c.init(Cipher.ENCRYPT_MODE, pubk);
byte[] pt1 = "demo text".substring(0, maxLenBytes).getBytes();
byte[] ct = c.doFinal(pt1);
Key privk = kp.getPrivate();
c.init(Cipher.DECRYPT_MODE, privk);
byte[] pt2 = c.doFinal(ct);
}
}
| 1,019
| 27.333333
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/secureConfigsRSA/src/main/java/example/SecureConfig128bitsRSA_4096x512_1.java
|
package example;
import javax.crypto.*;
import java.security.*;
import java.security.spec.*;
import javax.crypto.spec.*;
import javax.crypto.spec.PSource;
import org.bouncycastle.jce.provider.*;
public final class SecureConfig128bitsRSA_4096x512_1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 4096;
int hsize = 512;
int maxLenBytes = (ksize - 2 * hsize) / 8 - 2;
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(ksize);
KeyPair kp = kpg.generateKeyPair();
MGF1ParameterSpec mgf1ps = MGF1ParameterSpec.SHA512;
OAEPParameterSpec OAEPps = new OAEPParameterSpec("SHA-512", "MGF1", mgf1ps, PSource.PSpecified.DEFAULT);
Cipher c = Cipher.getInstance("RSA/None/OAEPPadding", "BC");
Key pubk = kp.getPublic();
c.init(Cipher.ENCRYPT_MODE, pubk, OAEPps);
byte[] pt1 = "demo text".substring(0, maxLenBytes).getBytes();
byte[] ct = c.doFinal(pt1);
Key privk = kp.getPrivate();
c.init(Cipher.DECRYPT_MODE, privk, OAEPps);
byte[] pt2 = c.doFinal(ct);
}
}
| 1,272
| 29.309524
| 106
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/secureConfigsRSA/src/main/java/example/SecureConfig128bitsRSA_4096x512_2.java
|
package example;
import javax.crypto.*;
import java.security.*;
import org.bouncycastle.jce.provider.*;
public final class SecureConfig128bitsRSA_4096x512_2 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 4096;
int hsize = 512;
int maxLenBytes = (ksize - 2 * hsize) / 8 - 2;
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(ksize);
KeyPair kp = kpg.generateKeyPair();
Cipher c = Cipher.getInstance("RSA/None/OAEPwithSHA512andMGF1Padding", "BC");
Key pubk = kp.getPublic();
c.init(Cipher.ENCRYPT_MODE, pubk);
byte[] pt1 = "demo text".substring(0, maxLenBytes).getBytes();
byte[] ct = c.doFinal(pt1);
Key privk = kp.getPrivate();
c.init(Cipher.DECRYPT_MODE, privk);
byte[] pt2 = c.doFinal(ct);
}
}
| 1,019
| 27.333333
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/secureConfigsRSA/src/main/java/example/SecureConfig192bitsRSA_7680x384_1.java
|
package example;
import javax.crypto.*;
import java.security.*;
import java.security.spec.*;
import javax.crypto.spec.*;
import javax.crypto.spec.PSource;
import org.bouncycastle.jce.provider.*;
public final class SecureConfig192bitsRSA_7680x384_1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 7680;
int hsize = 384;
int maxLenBytes = (ksize - 2 * hsize) / 8 - 2;
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(ksize);
KeyPair kp = kpg.generateKeyPair();
MGF1ParameterSpec mgf1ps = MGF1ParameterSpec.SHA384;
OAEPParameterSpec OAEPps = new OAEPParameterSpec("SHA-384", "MGF1", mgf1ps, PSource.PSpecified.DEFAULT);
Cipher c = Cipher.getInstance("RSA/None/OAEPPadding", "BC");
Key pubk = kp.getPublic();
c.init(Cipher.ENCRYPT_MODE, pubk, OAEPps);
byte[] pt1 = "demo text".substring(0, maxLenBytes).getBytes();
byte[] ct = c.doFinal(pt1);
Key privk = kp.getPrivate();
c.init(Cipher.DECRYPT_MODE, privk, OAEPps);
byte[] pt2 = c.doFinal(ct);
}
}
| 1,272
| 29.309524
| 106
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/secureConfigsRSA/src/main/java/example/SecureConfig192bitsRSA_7680x384_2.java
|
package example;
import javax.crypto.*;
import java.security.*;
import org.bouncycastle.jce.provider.*;
public final class SecureConfig192bitsRSA_7680x384_2 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 7680;
int hsize = 384;
int maxLenBytes = (ksize - 2 * hsize) / 8 - 2;
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(ksize);
KeyPair kp = kpg.generateKeyPair();
Cipher c = Cipher.getInstance("RSA/None/OAEPwithSHA384andMGF1Padding", "BC");
Key pubk = kp.getPublic();
c.init(Cipher.ENCRYPT_MODE, pubk);
byte[] pt1 = "demo text".substring(0, maxLenBytes).getBytes();
byte[] ct = c.doFinal(pt1);
Key privk = kp.getPrivate();
c.init(Cipher.DECRYPT_MODE, privk);
byte[] pt2 = c.doFinal(ct);
}
}
| 1,019
| 27.333333
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/secureConfigsRSA/src/main/java/example/SecureConfig192bitsRSA_7680x512_1.java
|
package example;
import javax.crypto.*;
import java.security.*;
import java.security.spec.*;
import javax.crypto.spec.*;
import javax.crypto.spec.PSource;
import org.bouncycastle.jce.provider.*;
public final class SecureConfig192bitsRSA_7680x512_1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 7680;
int hsize = 512;
int maxLenBytes = (ksize - 2 * hsize) / 8 - 2;
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(ksize);
KeyPair kp = kpg.generateKeyPair();
MGF1ParameterSpec mgf1ps = MGF1ParameterSpec.SHA512;
OAEPParameterSpec OAEPps = new OAEPParameterSpec("SHA-512", "MGF1", mgf1ps, PSource.PSpecified.DEFAULT);
Cipher c = Cipher.getInstance("RSA/None/OAEPPadding", "BC");
Key pubk = kp.getPublic();
c.init(Cipher.ENCRYPT_MODE, pubk, OAEPps);
byte[] pt1 = "demo text".substring(0, maxLenBytes).getBytes();
byte[] ct = c.doFinal(pt1);
Key privk = kp.getPrivate();
c.init(Cipher.DECRYPT_MODE, privk, OAEPps);
byte[] pt2 = c.doFinal(ct);
}
}
| 1,272
| 29.309524
| 106
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/secureConfigsRSA/src/main/java/example/SecureConfig192bitsRSA_7680x512_2.java
|
package example;
import javax.crypto.*;
import java.security.*;
import org.bouncycastle.jce.provider.*;
public final class SecureConfig192bitsRSA_7680x512_2 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 7680;
int hsize = 512;
int maxLenBytes = (ksize - 2 * hsize) / 8 - 2;
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(ksize);
KeyPair kp = kpg.generateKeyPair();
Cipher c = Cipher.getInstance("RSA/None/OAEPwithSHA512andMGF1Padding", "BC");
Key pubk = kp.getPublic();
c.init(Cipher.ENCRYPT_MODE, pubk);
byte[] pt1 = "demo text".substring(0, maxLenBytes).getBytes();
byte[] ct = c.doFinal(pt1);
Key privk = kp.getPrivate();
c.init(Cipher.DECRYPT_MODE, privk);
byte[] pt2 = c.doFinal(ct);
}
}
| 1,019
| 27.333333
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/secureStreamCipher/src/main/java/example/UseMacWithMaleableStream.java
|
package example;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.Arrays;
public final class UseMacWithMaleableStream {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] iv = new byte[16], k2 = new byte[16];
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(256);
Key k1 = g.generateKey();
(new SecureRandom()).nextBytes(iv);
(new SecureRandom()).nextBytes(k2);
SecretKeySpec sks2 = new SecretKeySpec(k2, "HMACSHA256");
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
Mac m = Mac.getInstance("HMACSHA256", "BC");
byte[] pt1 = "text demo".getBytes(), X;
boolean ok, ivo = true;
String s = "Encrypt-then-MAC(EtM): calcula a tag do criptograma";
m.init(sks2);
c.init(Cipher.ENCRYPT_MODE, k1, new IvParameterSpec(iv));
byte[] ct = c.doFinal(pt1);
byte[] ctPlusIV = ct.clone();
Arrays.concatenate(ctPlusIV, iv);
byte[] tag = m.doFinal(ctPlusIV);
if (ivo) {
X = "demo text 2".getBytes();
ct = "demo text 3".getBytes();
}
ctPlusIV = ct.clone();
Arrays.concatenate(ctPlusIV, iv);
ok = MessageDigest.isEqual(m.doFinal(ctPlusIV), tag);
if (ok) {
m.init(sks2);
c.init(Cipher.DECRYPT_MODE, k1, new IvParameterSpec(iv));
byte[] ptBeto = c.doFinal(ct);
}
}
}
| 1,654
| 29.648148
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_secp192k1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_secp192k1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp192k1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_secp192r1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_secp192r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp192r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_secp224k1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_secp224k1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp224k1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_secp224r1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_secp224r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp224r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_secp256k1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_secp256k1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp256k1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_secp256r1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_secp256r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp256r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_secp384r1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_secp384r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp384r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_secp521r1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_secp521r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp521r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_sect163k1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_sect163k1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect163k1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_sect163r1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_sect163r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect163r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_sect163r2.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_sect163r2 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect163r2");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_sect233k1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_sect233k1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect233k1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_sect233r1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_sect233r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect233r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_sect239k1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_sect239k1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect239k1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_sect283k1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_sect283k1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect283k1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_sect283r1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_sect283r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect283r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_sect409k1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_sect409k1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect409k1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_sect409r1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_sect409r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect409r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_sect571k1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_sect571k1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect571k1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptogooduses/securecurves/src/main/java/example/SecureCurve_sect571r1.java
|
package example;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.ECGenParameterSpec;
public final class SecureCurve_sect571r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect571r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 694
| 27.958333
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/ImproperKeyLen/src/main/java/pkm/ImproperKeyLen/ImproperKeySizeRSA1.java
|
package pkm.ImproperKeyLen;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
public final class ImproperKeySizeRSA1 {
public static void main(String args[]) {
try {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunJSSE");
kpg.initialize(512);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
}
}
}
| 498
| 23.95
| 73
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/ImproperKeyLen/src/main/java/pkm/ImproperKeyLen/ImproperKeySizeRSA2.java
|
package pkm.ImproperKeyLen;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
public final class ImproperKeySizeRSA2 {
public static void main(String args[]) {
try {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunJSSE");
kpg.initialize(1024);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
}
}
}
| 499
| 24
| 73
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/ImproperKeyLen/src/main/java/pkm/ImproperKeyLen/ImproperKeySizeRSA3.java
|
package pkm.ImproperKeyLen;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class ImproperKeySizeRSA3 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(384);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
}
}
}
| 637
| 25.583333
| 68
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/ImproperKeyLen/src/main/java/pkm/ImproperKeyLen/ImproperKeySizeRSA4.java
|
package pkm.ImproperKeyLen;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
public final class ImproperKeySizeRSA4 {
public static void main(String args[]) {
try {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunJSSE");
kpg.initialize(768);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
}
}
}
| 499
| 22.809524
| 73
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/ImproperKeyLen/src/main/java/pkm/ImproperKeyLen/ImproperKeySizeRSA5.java
|
package pkm.ImproperKeyLen;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class ImproperKeySizeRSA5 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(256);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
}
}
}
| 637
| 25.583333
| 68
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/ImproperKeyLen/src/main/java/pkm/ImproperKeyLen/ImproperKeySizeRSA6.java
|
package pkm.ImproperKeyLen;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class ImproperKeySizeRSA6 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(128);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
}
}
}
| 637
| 25.583333
| 68
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenInsecureHash/src/main/java/wc/brokenInsecureHash/InsecureHashes1.java
|
package wc.brokenInsecureHash;
import java.security.*;
public final class InsecureHashes1 {
static Object[] hashes = { "MD2", "MD5", "SHA" };
static MessageDigest md;
public static void main(String[] a) {
try {
md = MessageDigest.getInstance("MD2", "SUN");
String input = "";
md.update(input.getBytes());
byte[] output = md.digest();
input = "abc";
md.update(input.getBytes());
output = md.digest();
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
md = MessageDigest.getInstance("MD5", "SUN");
input = "";
md.update(input.getBytes());
output = md.digest();
input = "abc";
md.update(input.getBytes());
output = md.digest();
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
md = MessageDigest.getInstance("SHA", "SUN");
input = "";
md.update(input.getBytes());
output = md.digest();
input = "abc";
md.update(input.getBytes());
output = md.digest();
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
}
}
}
| 1,195
| 23.408163
| 66
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenInsecureHash/src/main/java/wc/brokenInsecureHash/InsecureHashes2.java
|
package wc.brokenInsecureHash;
import java.security.*;
public final class InsecureHashes2 {
static Object[] hashes = {"MD2","MD5","SHA"};
static MessageDigest md[] = new MessageDigest[hashes.length];
public static void main(String[] a) {
try {
for (int i = 0; i < md.length; i++) {
md[i] = MessageDigest.getInstance(hashes[i].toString(),"SUN");
String input = "";
md[i].update(input.getBytes());
byte[] output = md[i].digest();
input = "abc";
md[i].update(input.getBytes());
output = md[i].digest();
input = "abcdefghijklmnopqrstuvwxyz";
md[i].update(input.getBytes());
output = md[i].digest();
}
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
}
}
}
| 784
| 27.035714
| 70
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenInsecureHash/src/main/java/wc/brokenInsecureHash/InsecureHashes3.java
|
package wc.brokenInsecureHash;
import java.security.*;
public final class InsecureHashes3 {
static MessageDigest md;
public static void main(String[] a) {
try {
md = MessageDigest.getInstance("MD2","SUN");
String input = "";
md.update(input.getBytes());
byte[] output = md.digest();
input = "abc";
md.update(input.getBytes());
output = md.digest();
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
}
}
}
| 591
| 22.68
| 68
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenInsecureHash/src/main/java/wc/brokenInsecureHash/InsecureHashes4.java
|
package wc.brokenInsecureHash;
import java.security.*;
public final class InsecureHashes4 {
static MessageDigest md;
public static void main(String[] a) {
try {
md = MessageDigest.getInstance("MD5","SUN");
String input = "";
md.update(input.getBytes());
byte[] output = md.digest();
input = "abc";
md.update(input.getBytes());
output = md.digest();
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
}
}
}
| 591
| 22.68
| 68
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenInsecureHash/src/main/java/wc/brokenInsecureHash/InsecureHashes5.java
|
package wc.brokenInsecureHash;
import java.security.*;
public final class InsecureHashes5 {
static MessageDigest md;
public static void main(String[] a) {
try {
md = MessageDigest.getInstance("SHA","SUN");
String input = "";
md.update(input.getBytes());
byte[] output = md.digest();
input = "abc";
md.update(input.getBytes());
output = md.digest();
input = "abcdefghijklmnopqrstuvwxyz";
md.update(input.getBytes());
output = md.digest();
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
}
}
}
| 591
| 22.68
| 68
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenInsecureMAC/src/main/java/wc/brokenInsecureMAC/InsecureMAC1.java
|
package wc.brokenInsecureMAC;
import javax.crypto.*;
import java.security.*;
import javax.crypto.spec.*;
public final class InsecureMAC1 {
public static void main(String[] args) {
try {
KeyGenerator kg = KeyGenerator.getInstance("HMACMD5", "SunJCE");
SecretKey sk = kg.generateKey();
Mac mac = Mac.getInstance("HMACMD5", "SunJCE");
mac.init(sk);
String msg = "demo msg";
mac.update(msg.getBytes());
byte[] result = mac.doFinal();
byte[] key2 = sk.getEncoded();
SecretKeySpec ks = new SecretKeySpec(key2, "HMACMD5");
Mac mac2 = Mac.getInstance("HMACMD5", "SunJCE");
mac2.init(ks);
mac2.update(msg.getBytes());
byte[] result2 = mac2.doFinal();
kg = KeyGenerator.getInstance("HMACSHA1", "SunJCE");
sk = kg.generateKey();
mac = Mac.getInstance("HMACSHA1", "SunJCE");
mac.init(sk);
msg = "demo msg 2";
mac.update(msg.getBytes());
result = mac.doFinal();
key2 = sk.getEncoded();
ks = new SecretKeySpec(key2, "HMACSHA1");
mac2 = Mac.getInstance("HMACSHA1", "SunJCE");
mac2.init(ks);
mac2.update(msg.getBytes());
result2 = mac2.doFinal();
} catch (NoSuchAlgorithmException | InvalidKeyException | IllegalStateException | NoSuchProviderException e) {
}
}
}
| 1,240
| 27.204545
| 112
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenInsecureMAC/src/main/java/wc/brokenInsecureMAC/InsecureMAC2.java
|
package wc.brokenInsecureMAC;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import javax.crypto.*;
import javax.crypto.spec.*;
public final class InsecureMAC2 {
static Object[] macs = { "HMACSHA1", "HMACMD5" };
public static void main(String[] args) {
for (int i = 0; i < macs.length; i++) {
try {
KeyGenerator kg = KeyGenerator.getInstance(macs[i].toString(), "SunJCE");
SecretKey sk = kg.generateKey();
Mac mac = Mac.getInstance(macs[i].toString(), "SunJCE");
mac.init(sk);
String msg = "demo msg";
mac.update(msg.getBytes());
byte[] result = mac.doFinal();
byte[] key2 = sk.getEncoded();
SecretKeySpec ks = new SecretKeySpec(key2, macs[i].toString());
Mac mac2 = Mac.getInstance(macs[i].toString(), "SunJCE");
mac2.init(ks);
mac2.update(msg.getBytes());
byte[] result2 = mac2.doFinal();
} catch (NoSuchAlgorithmException | InvalidKeyException | IllegalStateException
| NoSuchProviderException e) {
}
}
}
}
| 1,076
| 28.916667
| 82
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenInsecureMAC/src/main/java/wc/brokenInsecureMAC/InsecureMAC3.java
|
package wc.brokenInsecureMAC;
import javax.crypto.*;
import java.security.*;
import javax.crypto.spec.*;
public final class InsecureMAC3 {
public static void main(String[] args) {
try {
KeyGenerator kg = KeyGenerator.getInstance("HMACMD5", "SunJCE");
SecretKey sk = kg.generateKey();
Mac mac = Mac.getInstance("HMACMD5", "SunJCE");
mac.init(sk);
String msg = "demo msg";
mac.update(msg.getBytes());
byte[] result = mac.doFinal();
byte[] key2 = sk.getEncoded();
SecretKeySpec ks = new SecretKeySpec(key2, "HMACMD5");
Mac mac2 = Mac.getInstance("HMACMD5", "SunJCE");
mac2.init(ks);
mac2.update(msg.getBytes());
byte[] result2 = mac2.doFinal();
} catch (NoSuchAlgorithmException | InvalidKeyException | IllegalStateException | NoSuchProviderException e) {
}
}
}
| 810
| 26.965517
| 112
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenInsecureMAC/src/main/java/wc/brokenInsecureMAC/InsecureMAC4.java
|
package wc.brokenInsecureMAC;
import javax.crypto.*;
import java.security.*;
import javax.crypto.spec.*;
public final class InsecureMAC4 {
public static void main(String[] args) {
try {
KeyGenerator kg = KeyGenerator.getInstance("HMACSHA1", "SunJCE");
SecretKey sk = kg.generateKey();
Mac mac = Mac.getInstance("HMACSHA1", "SunJCE");
mac.init(sk);
String msg = "demo msg";
mac.update(msg.getBytes());
byte[] result = mac.doFinal();
byte[] key2 = sk.getEncoded();
SecretKeySpec ks = new SecretKeySpec(key2, "HMACMD5");
Mac mac2 = Mac.getInstance("HMACMD5", "SunJCE");
mac2.init(ks);
mac2.update(msg.getBytes());
byte[] result2 = mac2.doFinal();
} catch (NoSuchAlgorithmException | InvalidKeyException | IllegalStateException | NoSuchProviderException e) {
}
}
}
| 813
| 26.133333
| 112
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenSSLorTLS/src/main/java/icv/brokenSSLorTLS/SSLClientDateCertValidation.java
|
package icv.brokenSSLorTLS;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Principal;
import java.security.SignatureException;
import java.security.cert.Certificate;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.X509Certificate;
import javax.net.ssl.*;
public final class SSLClientDateCertValidation {
public static void main(String[] args) throws Exception {
SSLSocket socket = null;
boolean ok = true;
try {
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
socket = (SSLSocket) factory.createSocket("www.google.com", 443);
socket.startHandshake();
SSLSession session = socket.getSession();
Principal peerPrincipal = session.getPeerPrincipal();
Certificate[] peerCertificates = session.getPeerCertificates();
if (peerCertificates != null && peerCertificates.length >= 2) {
((X509Certificate) peerCertificates[0]).checkValidity();
peerCertificates[0].verify(peerCertificates[1].getPublicKey());
}
} catch (CertificateExpiredException | CertificateNotYetValidException | NoSuchAlgorithmException
| InvalidKeyException | NoSuchProviderException | SignatureException e) {
ok = false;
}
}
}
| 1,378
| 31.833333
| 99
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenSSLorTLS/src/main/java/icv/brokenSSLorTLS/SSLClientNoPeerValidation.java
|
package icv.brokenSSLorTLS;
import java.security.Principal;
import java.security.cert.Certificate;
import javax.net.ssl.*;
public final class SSLClientNoPeerValidation {
public static void main(String[] args) throws Exception {
SSLSocket socket = null;
Boolean ok = true;
try {
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
socket = (SSLSocket) factory.createSocket("www.google.com", 443);
socket.startHandshake();
SSLSession session = socket.getSession();
Principal peerPrincipal = session.getPeerPrincipal();
Certificate[] peerCertificates = session.getPeerCertificates();
} catch (Exception e) {
ok = false;
}
}
}
| 688
| 23.607143
| 79
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenSSLorTLS/src/main/java/icv/brokenSSLorTLS/SSLClientOnlyCertPathValidation.java
|
package icv.brokenSSLorTLS;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import java.security.PublicKey;
import java.security.cert.CertPath;
import java.security.cert.CertPathValidator;
import java.security.cert.CertPathValidatorException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.PKIXCertPathValidatorResult;
import java.security.cert.PKIXParameters;
import java.security.cert.PolicyNode;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.net.ssl.*;
public final class SSLClientOnlyCertPathValidation {
public static void main(String[] args) throws Exception {
SSLSocket socket = null;
boolean ok = true;
try {
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
socket = (SSLSocket) factory.createSocket("www.google.com", 443);
socket.startHandshake();
SSLSession session = socket.getSession();
Principal peerPrincipal = session.getPeerPrincipal();
Certificate[] certs = session.getPeerCertificates();
X509Certificate[] x509certs = new X509Certificate[certs.length - 1];
for (int i = 0; i < certs.length - 1; i++) {
x509certs[i] = (X509Certificate) certs[i];
}
X509Certificate anchor = (X509Certificate) certs[certs.length - 1];
List l = Arrays.asList(x509certs);
CertificateFactory cf = CertificateFactory.getInstance("X.509", "SUN");
CertPath cp = cf.generateCertPath(l);
TrustAnchor ta = new TrustAnchor(anchor, null);
PKIXParameters params = new PKIXParameters(Collections.singleton(ta));
params.setRevocationEnabled(false);
CertPathValidator cpv = CertPathValidator.getInstance("PKIX", "SUN");
PKIXCertPathValidatorResult cpvr = (PKIXCertPathValidatorResult) cpv.validate(cp, params);
PolicyNode policyTree = cpvr.getPolicyTree();
PublicKey subjectPK = cpvr.getPublicKey();
} catch (CertificateException | InvalidAlgorithmParameterException | NoSuchAlgorithmException
| CertPathValidatorException e) {
ok = false;
}
}
}
| 2,278
| 34.609375
| 95
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenSSLorTLS/src/main/java/icv/brokenSSLorTLS/SSLClientOnlyCertValidation.java
|
package icv.brokenSSLorTLS;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Principal;
import java.security.SignatureException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import javax.net.ssl.*;
public final class SSLClientOnlyCertValidation {
public static void main(String[] args) throws Exception {
SSLSocket socket = null;
boolean ok = true;
try {
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault();
socket = (SSLSocket) factory.createSocket("www.google.com", 443);
socket.startHandshake();
SSLSession session = socket.getSession();
Principal peerPrincipal = session.getPeerPrincipal();
Certificate[] peerCertificates = session.getPeerCertificates();
if (peerCertificates != null && peerCertificates.length >= 2) {
peerCertificates[0].verify(peerCertificates[1].getPublicKey());
}
} catch (IOException | CertificateException | NoSuchAlgorithmException | InvalidKeyException
| NoSuchProviderException | SignatureException e) {
ok = false;
}
}
}
| 1,207
| 30.789474
| 94
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenSSLorTLS/src/main/java/icv/brokenSSLorTLS/SSLctxNoKeyMgmtNoTrustMgmt1.java
|
package icv.brokenSSLorTLS;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import java.security.SecureRandom;
import java.security.cert.Certificate;
import javax.net.ssl.*;
public final class SSLctxNoKeyMgmtNoTrustMgmt1 {
public static void main(String[] args) throws Exception {
SSLSocket socket = null;
Boolean ok = true;
try {
SSLContext sslctx = SSLContext.getInstance("TLS");
sslctx.init(new KeyManager[] {}, null, SecureRandom.getInstanceStrong());
SSLSocketFactory factory = sslctx.getSocketFactory();
socket = (SSLSocket) factory.createSocket("www.google.com", 443);
socket.startHandshake();
SSLSession session = socket.getSession();
Principal peerPrincipal = session.getPeerPrincipal();
Certificate[] peerCertificates = session.getPeerCertificates();
} catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {
ok = false;
}
}
}
| 1,009
| 27.055556
| 79
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenSSLorTLS/src/main/java/icv/brokenSSLorTLS/SSLctxNoKeyMgmtNoTrustMgmt2.java
|
package icv.brokenSSLorTLS;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import java.security.SecureRandom;
import java.security.cert.Certificate;
import javax.net.ssl.*;
public final class SSLctxNoKeyMgmtNoTrustMgmt2 {
public static void main(String[] args) throws Exception {
SSLSocket socket = null;
Boolean ok = true;
try {
SSLContext sslctx = SSLContext.getInstance("TLS");
sslctx.init(null, null, SecureRandom.getInstanceStrong());
SSLSocketFactory factory = sslctx.getSocketFactory();
socket = (SSLSocket) factory.createSocket("www.google.com", 443);
socket.startHandshake();
SSLSession session = socket.getSession();
Principal peerPrincipal = session.getPeerPrincipal();
Certificate[] peerCertificates = session.getPeerCertificates();
} catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {
ok = false;
}
}
}
| 994
| 26.638889
| 79
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenSSLorTLS/src/main/java/icv/brokenSSLorTLS/SSLctxNoKeyMgmtNoTrustMgmt3.java
|
package icv.brokenSSLorTLS;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import java.security.SecureRandom;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import javax.net.ssl.*;
public final class SSLctxNoKeyMgmtNoTrustMgmt3 {
public static void main(String[] args) throws Exception {
SSLSocket socket = null;
Boolean ok = true;
try {
SSLContext sslctx = SSLContext.getInstance("TLS");
TrustManager[] tac = { new TrustAllCerts() };
sslctx.init(null, tac, SecureRandom.getInstanceStrong());
SSLSocketFactory factory = sslctx.getSocketFactory();
socket = (SSLSocket) factory.createSocket("www.google.com", 443);
socket.startHandshake();
SSLSession session = socket.getSession();
Principal peerPrincipal = session.getPeerPrincipal();
Certificate[] peerCertificates = session.getPeerCertificates();
} catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {
ok = false;
}
}
}
class TrustAllCerts implements X509TrustManager {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] xcs, String string) {
}
@Override
public void checkServerTrusted(X509Certificate[] xcs, String string) {
}
}
class TrustAllHosts implements HostnameVerifier {
@Override
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
}
| 1,550
| 23.234375
| 79
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenSSLorTLS/src/main/java/icv/brokenSSLorTLS/SSLctxNoKeyMgmtNoTrustMgmt4.java
|
package icv.brokenSSLorTLS;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import java.security.SecureRandom;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import javax.net.ssl.*;
public final class SSLctxNoKeyMgmtNoTrustMgmt4 {
public static void main(String[] args) throws Exception {
SSLSocket socket = null;
Boolean ok = true;
try {
SSLContext sslctx = SSLContext.getInstance("TLS");
TrustManager[] tacah = { new TrustAllCertsAndHosts() };
sslctx.init(null, tacah, SecureRandom.getInstanceStrong());
SSLSocketFactory factory = sslctx.getSocketFactory();
socket = (SSLSocket) factory.createSocket("www.google.com", 443);
socket.startHandshake();
SSLSession session = socket.getSession();
Principal peerPrincipal = session.getPeerPrincipal();
Certificate[] peerCertificates = session.getPeerCertificates();
} catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {
ok = false;
}
}
}
class TrustAllCertsAndHosts implements X509TrustManager, HostnameVerifier {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] xcs, String string) {
}
@Override
public void checkServerTrusted(X509Certificate[] xcs, String string) {
}
@Override
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
}
| 1,534
| 24.583333
| 79
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenSSLorTLS/src/main/java/icv/brokenSSLorTLS/SSLctxNoKeyMgmtNoTrustMgmt5.java
|
package icv.brokenSSLorTLS;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import java.security.SecureRandom;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import javax.net.ssl.*;
public final class SSLctxNoKeyMgmtNoTrustMgmt5 {
public static void main(String[] args) throws Exception {
SSLSocket socket = null;
Boolean ok = true;
try {
SSLContext sslctx = SSLContext.getInstance("TLS");
TrustManager[] tacah = { new TrustAllCertsAndHosts() };
sslctx.init(null, tacah, SecureRandom.getInstanceStrong());
SSLSocketFactory factory = sslctx.getSocketFactory();
socket = (SSLSocket) factory.createSocket("www.google.com", 443);
socket.startHandshake();
SSLSession session = socket.getSession();
Principal peerPrincipal = session.getPeerPrincipal();
Certificate[] peerCertificates = session.getPeerCertificates();
} catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {
ok = false;
}
}
class InnerTrustAllCertsAndHosts implements X509TrustManager, HostnameVerifier {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] xcs, String string) {
}
@Override
public void checkServerTrusted(X509Certificate[] xcs, String string) {
}
@Override
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
}
}
| 1,556
| 24.52459
| 81
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/brokenSSLorTLS/src/main/java/icv/brokenSSLorTLS/SSLctxNoKeyMgmtNoTrustMgmt6.java
|
package icv.brokenSSLorTLS;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import java.security.SecureRandom;
import java.security.cert.Certificate;
import java.security.cert.X509Certificate;
import javax.net.ssl.*;
public final class SSLctxNoKeyMgmtNoTrustMgmt6 implements X509TrustManager, HostnameVerifier {
public static void main(String[] args) throws Exception {
SSLSocket socket = null;
Boolean ok = true;
try {
SSLContext sslctx = SSLContext.getInstance("TLS");
TrustManager[] tacah = { new TrustAllCertsAndHosts() };
sslctx.init(null, tacah, SecureRandom.getInstanceStrong());
SSLSocketFactory factory = sslctx.getSocketFactory();
socket = (SSLSocket) factory.createSocket("www.google.com", 443);
socket.startHandshake();
SSLSession session = socket.getSession();
Principal peerPrincipal = session.getPeerPrincipal();
Certificate[] peerCertificates = session.getPeerCertificates();
} catch (NoSuchAlgorithmException | KeyManagementException | IOException e) {
ok = false;
}
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] xcs, String string) {
}
@Override
public void checkServerTrusted(X509Certificate[] xcs, String string) {
}
@Override
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
}
| 1,501
| 25.350877
| 94
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/buggyIVgen/src/main/java/cib/buggyIVgen/BuggyIVGen1.java
|
package cib.buggyIVgen;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class BuggyIVGen1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] pt1 = ("demo text").getBytes();
byte[] iv = new byte[16];
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(128);
Key k = g.generateKey();
String[] aes = { "AES/OFB/NoPadding", "AES/CFB/NoPadding", "AES/CTR/NoPadding" };
boolean fixIV = true;
for (int a = 0; a < aes.length; a++) {
Cipher enc = Cipher.getInstance(aes[a], "BC");
Cipher dec = Cipher.getInstance(aes[a], "BC");
byte[][] ct = new byte[2][];
for (int i = 0; i < 2; i++) {
enc.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
ct[i] = enc.doFinal(pt1);
dec.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
byte[] pt2 = dec.doFinal(ct[i]);
if (!fixIV)
iv[iv.length - 1] = (byte) (iv[iv.length - 1] ^ 0x01);
}
}
}
}
| 1,660
| 32.897959
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/buggyIVgen/src/main/java/cib/buggyIVgen/BuggyIVGen2.java
|
package cib.buggyIVgen;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import java.util.Arrays;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class BuggyIVGen2 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] pt1 = ("demo text").getBytes();
byte[] iv = new byte[16];
Arrays.fill(iv, (byte) 0xAA);
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(128);
Key k = g.generateKey();
String[] aes = { "AES/OFB/NoPadding", "AES/CFB/NoPadding", "AES/CTR/NoPadding" };
boolean fixIV = true;
for (int a = 0; a < aes.length; a++) {
Cipher enc = Cipher.getInstance(aes[a], "BC");
Cipher dec = Cipher.getInstance(aes[a], "BC");
byte[][] ct = new byte[2][];
for (int i = 0; i < 2; i++) {
enc.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
ct[i] = enc.doFinal(pt1);
dec.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
byte[] pt2 = dec.doFinal(ct[i]);
if (!fixIV)
iv[iv.length - 1] = (byte) (iv[iv.length - 1] ^ 0x01);
}
}
}
}
| 1,716
| 33.34
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/constPwd4PBE/src/main/java/pkm/constPwd4PBE/ConstPassword4PBE1.java
|
package pkm.constPwd4PBE;
import javax.crypto.*;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.spec.PBEKeySpec;
import org.bouncycastle.jce.provider.*;
public final class ConstPassword4PBE1 {
public static void main(String args[]) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeySpecException,
InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
char[] password = "secretpass".toCharArray();
byte[] salt = new byte[16];
(new SecureRandom()).nextBytes(salt);
int iterationCount = 2048;
PBEKeySpec pbeks = new PBEKeySpec(password, salt, iterationCount);
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBEWithSHA1And128BitAES-CBC-BC", "BC");
Key sk = skf.generateSecret(pbeks);
Cipher c = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
c.init(Cipher.ENCRYPT_MODE, sk);
byte[] text1 = "demo text".getBytes();
byte[] ciphered = c.doFinal(text1);
c.init(Cipher.DECRYPT_MODE, sk);
byte[] text2 = c.doFinal(ciphered);
}
}
| 1,163
| 33.235294
| 117
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/constPwd4PBE/src/main/java/pkm/constPwd4PBE/ConstPassword4PBE2.java
|
package pkm.constPwd4PBE;
import javax.crypto.*;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.spec.PBEKeySpec;
import org.bouncycastle.jce.provider.*;
public final class ConstPassword4PBE2 {
public static void main(String args[]) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeySpecException,
InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
char[] password = new char[] { 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' };
byte[] salt = new byte[16];
(new SecureRandom()).nextBytes(salt);
int iterationCount = 2048;
PBEKeySpec pbeks = new PBEKeySpec(password, salt, iterationCount);
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBEWithSHA1And128BitAES-CBC-BC", "BC");
Key sk = skf.generateSecret(pbeks);
Cipher c = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
c.init(Cipher.ENCRYPT_MODE, sk);
byte[] text1 = "demo text".getBytes();
byte[] ciphered = c.doFinal(text1);
c.init(Cipher.DECRYPT_MODE, sk);
byte[] text2 = c.doFinal(ciphered);
}
}
| 1,190
| 34.029412
| 117
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/constantIV/src/main/java/ivm/constantIV/FixedIV1.java
|
package ivm.constantIV;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class FixedIV1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] pt1 = ("demo text").getBytes();
byte[] iv = "0123456789ABCDEF0123456789ABCDEF".getBytes();
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(128);
Key k = g.generateKey();
String[] aes = { "AES/OFB/NoPadding", "AES/CFB/NoPadding", "AES/CTR/NoPadding" };
boolean fixIV = true;
for (int a = 0; a < aes.length; a++) {
Cipher enc = Cipher.getInstance(aes[a], "BC");
Cipher dec = Cipher.getInstance(aes[a], "BC");
byte[][] ct = new byte[2][];
for (int i = 0; i < 2; i++) {
enc.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
ct[i] = enc.doFinal(pt1);
dec.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
byte[] pt2 = dec.doFinal(ct[i]);
if (!fixIV)
iv[iv.length - 1] = (byte) (iv[iv.length - 1] ^ 0x01);
}
}
}
}
| 1,687
| 35.695652
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/constantIV/src/main/java/ivm/constantIV/FixedIV2.java
|
package ivm.constantIV;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class FixedIV2 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] pt1 = ("demo text").getBytes();
byte[] iv = new byte[] { (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xAB,
(byte) 0xCD, (byte) 0xEF, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xAB,
(byte) 0xCD, (byte) 0xEF };
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(128);
Key k = g.generateKey();
String[] aes = { "AES/OFB/NoPadding", "AES/CFB/NoPadding", "AES/CTR/NoPadding" };
boolean fixIV = true;
for (int a = 0; a < aes.length; a++) {
Cipher enc = Cipher.getInstance(aes[a], "BC");
Cipher dec = Cipher.getInstance(aes[a], "BC");
byte[][] ct = new byte[2][];
for (int i = 0; i < 2; i++) {
enc.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
ct[i] = enc.doFinal(pt1);
dec.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
byte[] pt2 = dec.doFinal(ct[i]);
if (!fixIV)
iv[iv.length - 1] = (byte) (iv[iv.length - 1] ^ 0x01);
}
}
}
}
| 1,873
| 36.48
| 107
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/constantIV/src/main/java/ivm/constantIV/SimpleIVConstant.java
|
package ivm.constantIV;
import javax.crypto.spec.IvParameterSpec;
public class SimpleIVConstant {
public static void main(String[] args) {
byte[] iv = {1, 2, 0, 2, 1, 0, 8, 8, 1, 6, 1, 2, 1, 9, 9, 1};
IvParameterSpec constant = new IvParameterSpec(iv);
}
}
| 284
| 22.75
| 69
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/constantKey/src/main/java/pkm/constantKey/ConstantKey3DES.java
|
package pkm.constantKey;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public final class ConstantKey3DES {
public static void main(String[] a) {
try {
byte[] ck = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF".getBytes();
byte[] iv = new byte[8];
(new SecureRandom()).nextBytes(iv);
byte[] msg = "demo text".getBytes();
KeySpec ks = new DESedeKeySpec(ck);
SecretKeyFactory kf = SecretKeyFactory.getInstance("DESede", "SunJCE");
SecretKey k = kf.generateSecret(ks);
Cipher c = Cipher.getInstance("DESede/CTR/NoPadding", "SunJCE");
AlgorithmParameterSpec aps = new IvParameterSpec(iv);
c.init(Cipher.ENCRYPT_MODE, k, aps);
byte[] ct = c.doFinal(msg);
c.init(Cipher.DECRYPT_MODE, k, aps);
byte[] pt = c.doFinal(ct);
} catch (InvalidKeyException | NoSuchAlgorithmException | InvalidKeySpecException | NoSuchPaddingException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException
| NoSuchProviderException e) {
}
}
}
| 1,268
| 35.257143
| 108
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/constantKey/src/main/java/pkm/constantKey/ConstantKeyAES1.java
|
package pkm.constantKey;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public final class ConstantKeyAES1 {
public static void main(String[] a) {
try {
byte[] ck = { (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD,
(byte) 0xEF, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xAB,
(byte) 0xCD, (byte) 0xEF, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89,
(byte) 0xAB, (byte) 0xCD, (byte) 0xEF, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67,
(byte) 0x89, (byte) 0xAB, (byte) 0xCD, (byte) 0xEF };
byte[] iv = new byte[16];
(new SecureRandom()).nextBytes(iv);
byte[] msg = "demo text".getBytes();
SecretKeySpec ks = new SecretKeySpec(ck, "AES");
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "SunJCE");
AlgorithmParameterSpec aps = new IvParameterSpec(iv);
c.init(Cipher.ENCRYPT_MODE, ks, aps);
byte[] ct = c.doFinal(msg);
c.init(Cipher.DECRYPT_MODE, ks, aps);
byte[] pt = c.doFinal(ct);
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException
| NoSuchProviderException e) {
}
}
}
| 1,517
| 40.027027
| 107
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/constantKey/src/main/java/pkm/constantKey/ConstantKeyAES2.java
|
package pkm.constantKey;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public final class ConstantKeyAES2 {
public static void main(String[] a) {
try {
byte[] ck = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF".getBytes();
byte[] iv = new byte[16];
(new SecureRandom()).nextBytes(iv);
byte[] msg = "demo text".getBytes();
SecretKeySpec ks = new SecretKeySpec(ck, "AES");
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "SunJCE");
AlgorithmParameterSpec aps = new IvParameterSpec(iv);
c.init(Cipher.ENCRYPT_MODE, ks, aps);
byte[] ct = c.doFinal(msg);
c.init(Cipher.DECRYPT_MODE, ks, aps);
byte[] pt = c.doFinal(ct);
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException
| NoSuchProviderException e) {
}
}
}
| 1,156
| 34.060606
| 93
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/constantKey/src/main/java/pkm/constantKey/ConstantKeyAES3.java
|
package pkm.constantKey;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public final class ConstantKeyAES3 {
public static void main(String[] a) {
try {
byte[] ck = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF".getBytes();
byte[] iv = new byte[16];
(new SecureRandom()).nextBytes(iv);
byte[] msg = "demo text".getBytes();
SecretKeySpec ks = new SecretKeySpec(ck, "AES");
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "SunJCE");
AlgorithmParameterSpec aps = new IvParameterSpec(iv);
c.init(Cipher.ENCRYPT_MODE, ks, aps);
byte[] ct = c.doFinal(msg);
SecretKeySpec ks1 = new SecretKeySpec(ks.getEncoded(), "AES");
c.init(Cipher.DECRYPT_MODE, ks1, aps);
byte[] pt = c.doFinal(ct);
} catch (InvalidKeyException | NoSuchAlgorithmException | NoSuchPaddingException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException
| NoSuchProviderException e) {
}
}
}
| 1,223
| 35
| 93
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/constantKey/src/main/java/pkm/constantKey/ConstantKeyforMAC.java
|
package pkm.constantKey;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
public final class ConstantKeyforMAC {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
byte[] ck = { (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD,
(byte) 0xEF, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD,
(byte) 0xEF, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD,
(byte) 0xEF, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD,
(byte) 0xEF };
SecretKeySpec sks1 = new SecretKeySpec(ck, "HMACSHA256");
Mac m = Mac.getInstance("HMACSHA256", "SunJCE");
m.init(sks1);
byte[] msg1 = "This is a test for MAC".getBytes();
byte[] tag = m.doFinal(msg1);
SecretKeySpec sks = new SecretKeySpec(ck, "HMACSHA256");
m.init(sks);
byte[] tag2 = m.doFinal(msg1);
boolean ok = MessageDigest.isEqual(tag2, tag);
}
}
| 1,217
| 34.823529
| 107
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/constantKey/src/main/java/pkm/constantKey/HardCodedKey.java
|
package pkm.constantKey;
import javax.crypto.spec.SecretKeySpec;
public class HardCodedKey {
public static void main(String[] args) {
String a = "Key Part 1";
String b = "Key Part 2";
b = a + b;
byte[] keyBytes = b.getBytes();
SecretKeySpec key = new SecretKeySpec(keyBytes, "AES");
}
}
| 302
| 19.2
| 57
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/customCrypto/src/main/java/wc/customCrypto/Manual3DES.java
|
package wc.customCrypto;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public final class Manual3DES {
public static void main(String[] a) {
try {
String k1 = "0123456789ABCDEF";
String k2 = "1123456789ABCDEF";
String k3 = "2123456789ABCDEF";
byte[] k123 = (k1 + k2 + k3).getBytes();
byte[] iv = null;
byte[] msg = "demo msg".getBytes();
KeySpec ks = new DESedeKeySpec(k123);
SecretKeyFactory kf = SecretKeyFactory.getInstance("DESede", "SunJCE");
SecretKey k = kf.generateSecret(ks);
Cipher c = Cipher.getInstance("DESede", "SunJCE");
c.init(Cipher.ENCRYPT_MODE, k);
byte[] theCph = c.doFinal(msg);
c.init(Cipher.DECRYPT_MODE, k);
byte[] theClear = c.doFinal(theCph);
} catch (InvalidKeyException | NoSuchAlgorithmException | InvalidKeySpecException | NoSuchPaddingException
| IllegalBlockSizeException | BadPaddingException | NoSuchProviderException e) {
}
}
}
| 1,091
| 30.2
| 108
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/customCrypto/src/main/java/wc/customCrypto/RawSignatureRSA.java
|
package wc.customCrypto;
import java.security.*;
public final class RawSignatureRSA {
public static void main(String args[]) {
byte[] msg = "demo msg".getBytes();
try {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunJSSE");
kpg.initialize(2048);
KeyPair kp = kpg.generateKeyPair();
Signature sig = Signature.getInstance("SHA1WithRSA", "SunJSSE");
sig.initSign(kp.getPrivate());
sig.update(msg);
byte[] signed = sig.sign();
sig.initVerify(kp.getPublic());
sig.update(msg);
} catch (NoSuchAlgorithmException | NoSuchProviderException | InvalidKeyException | SignatureException e) {
}
}
}
| 642
| 26.956522
| 109
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/customCrypto/src/main/java/wc/customCrypto/RawSignatureRSAwHash.java
|
package wc.customCrypto;
import javax.crypto.Cipher;
import java.security.*;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
public final class RawSignatureRSAwHash {
public static void main(String args[]) {
byte[] msg = "demo msg".getBytes();
try {
MessageDigest md = MessageDigest.getInstance("SHA-512", "SUN");
md.update(msg);
byte[] digested = md.digest();
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "SunJSSE");
kpg.initialize(3072);
KeyPair kp = kpg.generateKeyPair();
Cipher ciph = Cipher.getInstance("RSA", "SunJCE");
ciph.init(Cipher.ENCRYPT_MODE, kp.getPrivate());
byte[] ciphered = ciph.doFinal(digested);
byte[] hashDigested = md.digest(msg);
ciph.init(Cipher.DECRYPT_MODE, kp.getPublic());
byte[] hashOriginal = ciph.doFinal(ciphered);
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException
| BadPaddingException | NoSuchProviderException e) {
}
}
}
| 1,071
| 31.484848
| 110
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/deterministicCrypto/src/main/java/pkc/enc/deterministicCrypto/DeterministicEncryptionRSA.java
|
package pkc.enc.deterministicCrypto;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class DeterministicEncryptionRSA {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[] text1 = ("demo text").getBytes();
KeyPairGenerator g = KeyPairGenerator.getInstance("RSA", "BC");
g.initialize(512);
KeyPair kp = g.generateKeyPair();
String[] rsa = { "RSA", "RSA/ECB/NoPadding", "RSA/None/NoPadding", "RSA/None/PKCS1Padding",
"RSA/None/OAEPWithSHA1AndMGF1Padding" };
for (int a = 0; a < rsa.length; a++) {
Cipher enc = Cipher.getInstance(rsa[a], "BC");
enc.init(Cipher.ENCRYPT_MODE, kp.getPublic());
Cipher dec = Cipher.getInstance(rsa[a], "BC");
dec.init(Cipher.DECRYPT_MODE, kp.getPrivate());
byte[][] bytearr = new byte[2][];
for (int i = 0; i < 2; i++) {
bytearr[i] = enc.doFinal(text1);
byte[] text2 = dec.doFinal(bytearr[i]);
}
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException
| BadPaddingException | NoSuchProviderException e) {
}
}
}
| 1,547
| 35
| 110
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/deterministicCrypto/src/main/java/pkc/enc/deterministicCrypto/DeterministicEncryptionRSA1.java
|
package pkc.enc.deterministicCrypto;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class DeterministicEncryptionRSA1 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[] text1 = ("demo text").getBytes();
KeyPairGenerator g = KeyPairGenerator.getInstance("RSA", "BC");
g.initialize(512);
KeyPair kp = g.generateKeyPair();
Cipher enc = Cipher.getInstance("RSA/ECB/NoPadding", "BC");
enc.init(Cipher.ENCRYPT_MODE, kp.getPublic());
Cipher dec = Cipher.getInstance("RSA/ECB/NoPadding", "BC");
dec.init(Cipher.DECRYPT_MODE, kp.getPrivate());
byte[][] bytearr = new byte[2][];
for (int i = 0; i < 2; i++) {
bytearr[i] = enc.doFinal(text1);
byte[] text2 = dec.doFinal(bytearr[i]);
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException
| BadPaddingException | NoSuchProviderException e) {
}
}
}
| 1,378
| 33.475
| 110
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/deterministicCrypto/src/main/java/pkc/enc/deterministicCrypto/DeterministicEncryptionRSA2.java
|
package pkc.enc.deterministicCrypto;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class DeterministicEncryptionRSA2 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[] text1 = ("demo text").getBytes();
KeyPairGenerator g = KeyPairGenerator.getInstance("RSA", "BC");
g.initialize(512);
KeyPair kp = g.generateKeyPair();
Cipher enc = Cipher.getInstance("RSA/None/NoPadding", "BC");
enc.init(Cipher.ENCRYPT_MODE, kp.getPublic());
Cipher dec = Cipher.getInstance("RSA/None/NoPadding", "BC");
dec.init(Cipher.DECRYPT_MODE, kp.getPrivate());
byte[][] bytearr = new byte[2][];
for (int i = 0; i < 2; i++) {
bytearr[i] = enc.doFinal(text1);
byte[] text2 = dec.doFinal(bytearr[i]);
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException
| BadPaddingException | NoSuchProviderException e) {
}
}
}
| 1,380
| 33.525
| 110
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/deterministicCrypto/src/main/java/pkc/enc/deterministicCrypto/DeterministicEncryptionRSA3.java
|
package pkc.enc.deterministicCrypto;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class DeterministicEncryptionRSA3 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[] text1 = ("demo text").getBytes();
KeyPairGenerator g = KeyPairGenerator.getInstance("RSA", "BC");
g.initialize(512);
KeyPair kp = g.generateKeyPair();
Cipher enc = Cipher.getInstance("RSA/NONE/NoPadding", "BC");
enc.init(Cipher.ENCRYPT_MODE, kp.getPublic());
Cipher dec = Cipher.getInstance("RSA/NONE/NoPadding", "BC");
dec.init(Cipher.DECRYPT_MODE, kp.getPrivate());
byte[][] bytearr = new byte[2][];
for (int i = 0; i < 2; i++) {
bytearr[i] = enc.doFinal(text1);
byte[] text2 = dec.doFinal(bytearr[i]);
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException
| BadPaddingException | NoSuchProviderException e) {
}
}
}
| 1,381
| 32.707317
| 110
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/deterministicSymEnc/src/main/java/wc/deterministicSymEnc/DeterministicEncryptionAESwECB1.java
|
package wc.deterministicSymEnc;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class DeterministicEncryptionAESwECB1 {
public static void main(String args[]) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException, NoSuchProviderException {
Security.addProvider(new BouncyCastleProvider());
byte[] text1 = ("demo text").getBytes();
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(256);
Key k = g.generateKey();
Cipher enc = Cipher.getInstance("AES/ECB/NoPadding", "BC");
enc.init(Cipher.ENCRYPT_MODE, k);
Cipher dec = Cipher.getInstance("AES/ECB/NoPadding", "BC");
dec.init(Cipher.DECRYPT_MODE, k);
byte[][] bytearr = new byte[2][];
for (int i = 0; i < 2; i++) {
bytearr[i] = enc.doFinal(text1);
byte[] decrypted1 = dec.doFinal(bytearr[i]);
}
enc = Cipher.getInstance("AES/ECB/PKCS5Padding", "BC");
enc.init(Cipher.ENCRYPT_MODE, k);
dec = Cipher.getInstance("AES/ECB/PKCS5Padding", "BC");
dec.init(Cipher.DECRYPT_MODE, k);
bytearr = new byte[2][];
for (int i = 0; i < 2; i++) {
bytearr[i] = enc.doFinal(text1);
byte[] decrypted2 = dec.doFinal(bytearr[i]);
}
enc = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
enc.init(Cipher.ENCRYPT_MODE, k);
dec = Cipher.getInstance("AES/ECB/PKCS7Padding", "BC");
dec.init(Cipher.DECRYPT_MODE, k);
bytearr = new byte[2][];
for (int i = 0; i < 2; i++) {
bytearr[i] = enc.doFinal(text1);
byte[] decrypted3 = dec.doFinal(bytearr[i]);
}
}
}
| 1,957
| 31.633333
| 117
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/deterministicSymEnc/src/main/java/wc/deterministicSymEnc/DeterministicEncryptionAESwECB2.java
|
package wc.deterministicSymEnc;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class DeterministicEncryptionAESwECB2 {
public static void main(String args[]) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException, NoSuchProviderException {
Security.addProvider(new BouncyCastleProvider());
byte[] text1 = ("demo text").getBytes();
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(256);
Key k = g.generateKey();
String[] aes = { "AES/ECB/NoPadding", "AES/ECB/PKCS5Padding", "AES/ECB/PKCS7Padding" };
for (int a = 0; a < aes.length; a++) {
Cipher enc = Cipher.getInstance(aes[a], "BC");
enc.init(Cipher.ENCRYPT_MODE, k);
Cipher dec = Cipher.getInstance(aes[a], "BC");
dec.init(Cipher.DECRYPT_MODE, k);
byte[][] bytearr = new byte[2][];
for (int i = 0; i < 2; i++) {
bytearr[i] = enc.doFinal(text1);
byte[] decrypted = dec.doFinal(bytearr[i]);
}
}
}
}
| 1,399
| 34
| 117
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/fixedSeed/src/main/java/br/fixedSeed/FixedSeed1.java
|
package br.fixedSeed;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.IvParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class FixedSeed1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] pt1 = ("demo text").getBytes();
byte[] seed = { (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD,
(byte) 0xEF, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xAB, (byte) 0xCD,
(byte) 0xEF };
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(128);
Key k = g.generateKey();
String[] aes = { "AES/OFB/NoPadding", "AES/CFB/NoPadding", "AES/CTR/NoPadding" };
for (int a = 0; a < aes.length; a++) {
Cipher enc = Cipher.getInstance(aes[a], "BC");
Cipher dec = Cipher.getInstance(aes[a], "BC");
byte[][] ct = new byte[2][];
for (int i = 0; i < 2; i++) {
SecureRandom sr1 = SecureRandom.getInstance("SHA1PRNG", "SUN");
sr1.setSeed(seed);
enc.init(Cipher.ENCRYPT_MODE, k, sr1);
ct[i] = enc.doFinal(pt1);
dec.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(enc.getIV()));
byte[] pt2 = dec.doFinal(ct[i]);
}
for (int i = 0; i < 2; i++) {
SecureRandom sr2 = SecureRandom.getInstance("Windows-PRNG", "SunMSCAPI");
sr2.setSeed(seed);
enc.init(Cipher.ENCRYPT_MODE, k, sr2);
ct[i] = enc.doFinal(pt1);
dec.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(enc.getIV()));
byte[] pt2 = dec.doFinal(ct[i]);
}
}
}
}
| 2,201
| 36.322034
| 108
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/fixedSeed/src/main/java/br/fixedSeed/FixedSeed2.java
|
package br.fixedSeed;
import java.security.SecureRandom;
public final class FixedSeed2 {
public static void main(String[] args) {
try {
final int fixedSeed = 10;
SecureRandom r3 = SecureRandom.getInstanceStrong();
r3.setSeed(10);
SecureRandom r4 = SecureRandom.getInstanceStrong();
r4.setSeed(fixedSeed);
} catch (Exception e) {
}
}
}
| 362
| 18.105263
| 54
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/fixedSeed/src/main/java/br/fixedSeed/FixedSeed3.java
|
package br.fixedSeed;
import java.security.SecureRandom;
public final class FixedSeed3 {
public static void main(String[] args) {
try {
byte[] fixedSeed = { (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89, (byte) 0xAB,
(byte) 0xCD, (byte) 0xEF, (byte) 0x01, (byte) 0x23, (byte) 0x45, (byte) 0x67, (byte) 0x89,
(byte) 0xAB, (byte) 0xCD, (byte) 0xEF };
SecureRandom r3 = SecureRandom.getInstanceStrong();
r3.setSeed(10);
SecureRandom r4 = SecureRandom.getInstanceStrong();
r4.setSeed(fixedSeed);
} catch (Exception e) {
}
}
}
| 578
| 25.318182
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/fixedSeed/src/main/java/br/fixedSeed/FixedSeed4.java
|
package br.fixedSeed;
import java.security.SecureRandom;
public final class FixedSeed4 {
public static void main(String[] args) {
try {
byte[] fixedSeed = "0123456789ABCDEF0123456789ABCDEF".getBytes();
SecureRandom r3 = SecureRandom.getInstanceStrong();
r3.setSeed(10);
SecureRandom r4 = SecureRandom.getInstanceStrong();
r4.setSeed(fixedSeed);
} catch (Exception e) {
}
}
}
| 403
| 19.2
| 68
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/incompleteValidation/src/main/java/icv/incompleteValidation/NoValidationAtAll.java
|
package icv.incompleteValidation;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
import java.security.SignatureException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Date;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.BasicConstraints;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.KeyUsage;
import org.bouncycastle.cert.CertIOException;
import org.bouncycastle.cert.X509v1CertificateBuilder;
import org.bouncycastle.cert.X509v3CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
import org.bouncycastle.cert.jcajce.JcaX509v1CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
public final class NoValidationAtAll {
private static final int oneSecond = 1000;
private static final int oneMinute = oneSecond * 60;
private static final int oneHour = oneMinute * 60;
private static final int oneDay = oneHour * 24;
private static final int oneWeek = oneDay * 7;
private static final int validity = oneWeek;
private static int serialNumberCounter = 1;
public static boolean validate(X509Certificate cert, X509Certificate ca, X500Principal issuer, X500Principal subj,
Date date) {
boolean ok = false;
ok = true;
if (ok) {
try {
ok = false;
cert.verify(ca.getPublicKey());
ok = true;
} catch (CertificateException ex) {
ok = false;
} catch (NoSuchAlgorithmException | InvalidKeyException | NoSuchProviderException | SignatureException ex) {
ok = false;
}
}
return ok;
}
public static void main(String[] args) {
Security.addProvider(new BouncyCastleProvider());
try {
KeyPair rkp = genRSAKeyPair();
X509Certificate root = buildSelfSignedCert(rkp);
KeyPair mkp = genRSAKeyPair();
X509Certificate middle = buildMiddleCert(mkp.getPublic(), "CN=Intermediate CA Certificate",
rkp.getPrivate(), root);
KeyPair ekp = genRSAKeyPair();
X509Certificate user = buildEndCert(ekp.getPublic(), "CN=End User Certificate", mkp.getPrivate(),
middle);
X500Principal issuer = new X500Principal("CN=Root Certificate");
X500Principal subj1 = new X500Principal("CN=Intermediate CA Certificate");
X500Principal subj2 = new X500Principal("CN=End User Certificate");
boolean ok = false;
ok = validate(user, middle, subj1, subj2, null);
} catch (Exception ex) {
}
}
public static KeyPair genRSAKeyPair() throws Exception {
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
kpGen.initialize(2048, new SecureRandom());
return kpGen.generateKeyPair();
}
public static X509Certificate buildSelfSignedCert(KeyPair keyPair) throws Exception {
X509v1CertificateBuilder certBldr = new JcaX509v1CertificateBuilder(new X500Name("CN=Root Certificate"),
BigInteger.valueOf(1), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + oneWeek), new X500Name("CN=Root Certificate"),
keyPair.getPublic());
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(keyPair.getPrivate());
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
X509Certificate cert = jX509c.getCertificate(certBldr.build(signer));
return cert;
}
public static X509Certificate buildMiddleCert(PublicKey pk, String cn, PrivateKey caKey, X509Certificate cac)
throws NoSuchAlgorithmException, CertIOException, OperatorCreationException, CertificateException {
X509Certificate cert = null;
X509v3CertificateBuilder cb = new JcaX509v3CertificateBuilder(cac.getSubjectX500Principal(),
BigInteger.valueOf(serialNumberCounter++), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + validity), new X500Principal(cn), pk);
JcaX509ExtensionUtils utils;
utils = new JcaX509ExtensionUtils();
cb.addExtension(Extension.authorityKeyIdentifier, false, utils.createAuthorityKeyIdentifier(cac));
cb.addExtension(Extension.subjectKeyIdentifier, false, utils.createSubjectKeyIdentifier(pk));
cb.addExtension(Extension.basicConstraints, true, new BasicConstraints(0));
cb.addExtension(Extension.keyUsage, true,
new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyCertSign | KeyUsage.cRLSign));
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(caKey);
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
cert = jX509c.getCertificate(cb.build(signer));
return cert;
}
public static X509Certificate buildEndCert(PublicKey pk, String cn, PrivateKey caKey, X509Certificate ca) {
X509Certificate cert = null;
try {
X509v3CertificateBuilder cb = new JcaX509v3CertificateBuilder(ca.getSubjectX500Principal(),
BigInteger.valueOf(serialNumberCounter++), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + validity), new X500Principal(cn), pk);
JcaX509ExtensionUtils utils;
utils = new JcaX509ExtensionUtils();
cb.addExtension(Extension.authorityKeyIdentifier, false, utils.createAuthorityKeyIdentifier(ca));
cb.addExtension(Extension.subjectKeyIdentifier, false, utils.createSubjectKeyIdentifier(pk));
cb.addExtension(Extension.basicConstraints, true, new BasicConstraints(false));
cb.addExtension(Extension.keyUsage, true,
new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment));
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(caKey);
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
cert = jX509c.getCertificate(cb.build(signer));
} catch (NoSuchAlgorithmException | CertIOException | OperatorCreationException | CertificateException ex) {
}
return cert;
}
}
| 6,690
| 37.901163
| 115
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/incompleteValidation/src/main/java/icv/incompleteValidation/NoValidationCaPubKey.java
|
package icv.incompleteValidation;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
import java.security.SignatureException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.X509Certificate;
import java.util.Date;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.BasicConstraints;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.KeyUsage;
import org.bouncycastle.cert.CertIOException;
import org.bouncycastle.cert.X509v1CertificateBuilder;
import org.bouncycastle.cert.X509v3CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
import org.bouncycastle.cert.jcajce.JcaX509v1CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
public final class NoValidationCaPubKey {
private static final int oneSecond = 1000;
private static final int oneMinute = oneSecond * 60;
private static final int oneHour = oneMinute * 60;
private static final int oneDay = oneHour * 24;
private static final int oneWeek = oneDay * 7;
private static final int validity = oneWeek;
private static int serialNumberCounter = 1;
public static boolean validate(X509Certificate cert, X509Certificate ca, X500Principal issuer, X500Principal subj,
Date date) {
boolean ok = false;
try {
if (date != null) {
cert.checkValidity(date);
} else {
cert.checkValidity();
}
ok = true;
} catch (CertificateExpiredException | CertificateNotYetValidException ex) {
ok = false;
}
if (ok) {
try {
ok = false;
cert.verify(ca.getPublicKey());
ok = true;
} catch (CertificateException ex) {
ok = false;
} catch (NoSuchAlgorithmException | InvalidKeyException | NoSuchProviderException | SignatureException ex) {
ok = false;
}
}
if (ok) {
ok = false;
if (cert.getIssuerX500Principal().equals(issuer)) {
ok = true;
} else {
ok = false;
}
if (ok && cert.getSubjectX500Principal().equals(subj)) {
ok = true;
} else {
ok = false;
}
}
return ok;
}
public static void main(String[] args) {
Security.addProvider(new BouncyCastleProvider());
try {
KeyPair rkp = genRSAKeyPair();
X509Certificate root = buildSelfSignedCert(rkp);
KeyPair mkp = genRSAKeyPair();
X509Certificate middle = buildMiddleCert(mkp.getPublic(), "CN=Intermediate CA Certificate",
rkp.getPrivate(), root);
KeyPair ekp = genRSAKeyPair();
X509Certificate user = buildEndCert(ekp.getPublic(), "CN=End User Certificate", mkp.getPrivate(), middle);
X500Principal issuer = new X500Principal("CN=Root Certificate");
X500Principal subj1 = new X500Principal("CN=Intermediate CA Certificate");
X500Principal subj2 = new X500Principal("CN=End User Certificate");
boolean ok = false;
ok = validate(user, middle, subj1, subj2, null);
} catch (Exception ex) {
}
}
public static KeyPair genRSAKeyPair() throws Exception {
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
kpGen.initialize(2048, new SecureRandom());
return kpGen.generateKeyPair();
}
public static X509Certificate buildSelfSignedCert(KeyPair keyPair) throws Exception {
X509v1CertificateBuilder certBldr = new JcaX509v1CertificateBuilder(new X500Name("CN=Root Certificate"),
BigInteger.valueOf(1), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + oneWeek), new X500Name("CN=Root Certificate"),
keyPair.getPublic());
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(keyPair.getPrivate());
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
X509Certificate cert = jX509c.getCertificate(certBldr.build(signer));
return cert;
}
public static X509Certificate buildMiddleCert(PublicKey pk, String cn, PrivateKey caKey, X509Certificate cac)
throws NoSuchAlgorithmException, CertIOException, OperatorCreationException, CertificateException {
X509Certificate cert = null;
X509v3CertificateBuilder cb = new JcaX509v3CertificateBuilder(cac.getSubjectX500Principal(),
BigInteger.valueOf(serialNumberCounter++), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + validity), new X500Principal(cn), pk);
JcaX509ExtensionUtils utils;
utils = new JcaX509ExtensionUtils();
cb.addExtension(Extension.authorityKeyIdentifier, false, utils.createAuthorityKeyIdentifier(cac));
cb.addExtension(Extension.subjectKeyIdentifier, false, utils.createSubjectKeyIdentifier(pk));
cb.addExtension(Extension.basicConstraints, true, new BasicConstraints(0));
cb.addExtension(Extension.keyUsage, true,
new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyCertSign | KeyUsage.cRLSign));
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(caKey);
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
cert = jX509c.getCertificate(cb.build(signer));
return cert;
}
public static X509Certificate buildEndCert(PublicKey pk, String cn, PrivateKey caKey, X509Certificate ca) {
X509Certificate cert = null;
try {
X509v3CertificateBuilder cb = new JcaX509v3CertificateBuilder(ca.getSubjectX500Principal(),
BigInteger.valueOf(serialNumberCounter++), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + validity), new X500Principal(cn), pk);
JcaX509ExtensionUtils utils;
utils = new JcaX509ExtensionUtils();
cb.addExtension(Extension.authorityKeyIdentifier, false, utils.createAuthorityKeyIdentifier(ca));
cb.addExtension(Extension.subjectKeyIdentifier, false, utils.createSubjectKeyIdentifier(pk));
cb.addExtension(Extension.basicConstraints, true, new BasicConstraints(false));
cb.addExtension(Extension.keyUsage, true,
new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment));
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(caKey);
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
cert = jX509c.getCertificate(cb.build(signer));
} catch (NoSuchAlgorithmException | CertIOException | OperatorCreationException | CertificateException ex) {
}
return cert;
}
}
| 7,247
| 36.169231
| 115
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/incompleteValidation/src/main/java/icv/incompleteValidation/NoValidationCertDates.java
|
package icv.incompleteValidation;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
import java.security.SignatureException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.Date;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.BasicConstraints;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.KeyUsage;
import org.bouncycastle.cert.CertIOException;
import org.bouncycastle.cert.X509v1CertificateBuilder;
import org.bouncycastle.cert.X509v3CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
import org.bouncycastle.cert.jcajce.JcaX509v1CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
public final class NoValidationCertDates {
private static final int oneSecond = 1000;
private static final int oneMinute = oneSecond * 60;
private static final int oneHour = oneMinute * 60;
private static final int oneDay = oneHour * 24;
private static final int oneWeek = oneDay * 7;
private static final int validity = oneWeek;
private static int serialNumberCounter = 1;
public static boolean validate(X509Certificate cert, X509Certificate ca, X500Principal issuer, X500Principal subj,
Date date) {
boolean ok = false;
ok = true;
if (ok) {
try {
ok = false;
cert.verify(ca.getPublicKey());
ok = true;
} catch (CertificateException ex) {
ok = false;
} catch (NoSuchAlgorithmException | InvalidKeyException | NoSuchProviderException | SignatureException ex) {
ok = false;
}
}
if (ok) {
ok = false;
if (cert.getIssuerX500Principal().equals(issuer)) {
ok = true;
} else {
ok = false;
}
if (ok && cert.getSubjectX500Principal().equals(subj)) {
ok = true;
} else {
ok = false;
}
}
return ok;
}
public static void main(String[] args) {
Security.addProvider(new BouncyCastleProvider());
try {
KeyPair rkp = genRSAKeyPair();
X509Certificate root = buildSelfSignedCert(rkp);
KeyPair mkp = genRSAKeyPair();
X509Certificate middle = buildMiddleCert(mkp.getPublic(), "CN=Intermediate CA Certificate",
rkp.getPrivate(), root);
KeyPair ekp = genRSAKeyPair();
X509Certificate user = buildEndCert(ekp.getPublic(), "CN=End User Certificate", mkp.getPrivate(), middle);
X500Principal issuer = new X500Principal("CN=Root Certificate");
X500Principal subj1 = new X500Principal("CN=Intermediate CA Certificate");
X500Principal subj2 = new X500Principal("CN=End User Certificate");
boolean ok = false;
ok = validate(middle, root, issuer, subj1, null);
ok = validate(user, middle, subj1, subj2, null);
} catch (Exception ex) {
}
}
public static KeyPair genRSAKeyPair() throws Exception {
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
kpGen.initialize(2048, new SecureRandom());
return kpGen.generateKeyPair();
}
public static X509Certificate buildSelfSignedCert(KeyPair keyPair) throws Exception {
X509v1CertificateBuilder certBldr = new JcaX509v1CertificateBuilder(new X500Name("CN=Root Certificate"),
BigInteger.valueOf(1), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + oneWeek), new X500Name("CN=Root Certificate"),
keyPair.getPublic());
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(keyPair.getPrivate());
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
X509Certificate cert = jX509c.getCertificate(certBldr.build(signer));
return cert;
}
public static X509Certificate buildMiddleCert(PublicKey pk, String cn, PrivateKey caKey, X509Certificate cac)
throws NoSuchAlgorithmException, CertIOException, OperatorCreationException, CertificateException {
X509Certificate cert = null;
X509v3CertificateBuilder cb = new JcaX509v3CertificateBuilder(cac.getSubjectX500Principal(),
BigInteger.valueOf(serialNumberCounter++), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + validity), new X500Principal(cn), pk);
JcaX509ExtensionUtils utils;
utils = new JcaX509ExtensionUtils();
cb.addExtension(Extension.authorityKeyIdentifier, false, utils.createAuthorityKeyIdentifier(cac));
cb.addExtension(Extension.subjectKeyIdentifier, false, utils.createSubjectKeyIdentifier(pk));
cb.addExtension(Extension.basicConstraints, true, new BasicConstraints(0));
cb.addExtension(Extension.keyUsage, true,
new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyCertSign | KeyUsage.cRLSign));
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(caKey);
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
cert = jX509c.getCertificate(cb.build(signer));
return cert;
}
public static X509Certificate buildEndCert(PublicKey pk, String cn, PrivateKey caKey, X509Certificate ca) {
X509Certificate cert = null;
try {
X509v3CertificateBuilder cb = new JcaX509v3CertificateBuilder(ca.getSubjectX500Principal(),
BigInteger.valueOf(serialNumberCounter++), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + validity), new X500Principal(cn), pk);
JcaX509ExtensionUtils utils;
utils = new JcaX509ExtensionUtils();
cb.addExtension(Extension.authorityKeyIdentifier, false, utils.createAuthorityKeyIdentifier(ca));
cb.addExtension(Extension.subjectKeyIdentifier, false, utils.createSubjectKeyIdentifier(pk));
cb.addExtension(Extension.basicConstraints, true, new BasicConstraints(false));
cb.addExtension(Extension.keyUsage, true,
new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment));
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(caKey);
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
cert = jX509c.getCertificate(cb.build(signer));
} catch (NoSuchAlgorithmException | CertIOException | OperatorCreationException | CertificateException ex) {
}
return cert;
}
}
| 6,984
| 36.756757
| 115
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/incompleteValidation/src/main/java/icv/incompleteValidation/NoValidationIssuerOrSubject.java
|
package icv.incompleteValidation;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
import java.security.SignatureException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateExpiredException;
import java.security.cert.CertificateNotYetValidException;
import java.security.cert.X509Certificate;
import java.util.Date;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.BasicConstraints;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.KeyUsage;
import org.bouncycastle.cert.CertIOException;
import org.bouncycastle.cert.X509v1CertificateBuilder;
import org.bouncycastle.cert.X509v3CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
import org.bouncycastle.cert.jcajce.JcaX509v1CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
public final class NoValidationIssuerOrSubject {
private static final int oneSecond = 1000;
private static final int oneMinute = oneSecond * 60;
private static final int oneHour = oneMinute * 60;
private static final int oneDay = oneHour * 24;
private static final int oneWeek = oneDay * 7;
private static final int validity = oneWeek;
private static int serialNumberCounter = 1;
public static boolean validate(X509Certificate cert, X509Certificate ca, X500Principal issuer, X500Principal subj,
Date date) {
boolean ok = false;
try {
if (date != null) {
cert.checkValidity(date);
} else {
cert.checkValidity();
}
ok = true;
} catch (CertificateExpiredException | CertificateNotYetValidException ex) {
ok = false;
}
if (ok) {
try {
ok = false;
cert.verify(ca.getPublicKey());
ok = true;
} catch (CertificateException ex) {
ok = false;
} catch (NoSuchAlgorithmException | InvalidKeyException | NoSuchProviderException | SignatureException ex) {
ok = false;
}
}
return ok;
}
public static void main(String[] args) {
Security.addProvider(new BouncyCastleProvider());
try {
KeyPair rkp = genRSAKeyPair();
X509Certificate root = buildSelfSignedCert(rkp);
KeyPair mkp = genRSAKeyPair();
X509Certificate middle = buildMiddleCert(mkp.getPublic(), "CN=Intermediate CA Certificate",
rkp.getPrivate(), root);
KeyPair ekp = genRSAKeyPair();
X509Certificate user = buildEndCert(ekp.getPublic(), "CN=End User Certificate", mkp.getPrivate(), middle);
X500Principal issuer = new X500Principal("CN=Root Certificate");
X500Principal subj1 = new X500Principal("CN=Intermediate CA Certificate");
X500Principal subj2 = new X500Principal("CN=End User Certificate");
boolean ok = false;
ok = validate(middle, root, issuer, subj1, null);
ok = validate(user, middle, subj1, subj2, null);
} catch (Exception ex) {
}
}
public static KeyPair genRSAKeyPair() throws Exception {
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
kpGen.initialize(2048, new SecureRandom());
return kpGen.generateKeyPair();
}
public static X509Certificate buildSelfSignedCert(KeyPair keyPair) throws Exception {
X509v1CertificateBuilder certBldr = new JcaX509v1CertificateBuilder(new X500Name("CN=Root Certificate"),
BigInteger.valueOf(1), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + oneWeek), new X500Name("CN=Root Certificate"),
keyPair.getPublic());
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(keyPair.getPrivate());
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
X509Certificate cert = jX509c.getCertificate(certBldr.build(signer));
return cert;
}
public static X509Certificate buildMiddleCert(PublicKey pk, String cn, PrivateKey caKey, X509Certificate cac)
throws NoSuchAlgorithmException, CertIOException, OperatorCreationException, CertificateException {
X509Certificate cert = null;
X509v3CertificateBuilder cb = new JcaX509v3CertificateBuilder(cac.getSubjectX500Principal(),
BigInteger.valueOf(serialNumberCounter++), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + validity), new X500Principal(cn), pk);
JcaX509ExtensionUtils utils;
utils = new JcaX509ExtensionUtils();
cb.addExtension(Extension.authorityKeyIdentifier, false, utils.createAuthorityKeyIdentifier(cac));
cb.addExtension(Extension.subjectKeyIdentifier, false, utils.createSubjectKeyIdentifier(pk));
cb.addExtension(Extension.basicConstraints, true, new BasicConstraints(0));
cb.addExtension(Extension.keyUsage, true,
new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyCertSign | KeyUsage.cRLSign));
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(caKey);
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
cert = jX509c.getCertificate(cb.build(signer));
return cert;
}
public static X509Certificate buildEndCert(PublicKey pk, String cn, PrivateKey caKey, X509Certificate ca) {
X509Certificate cert = null;
try {
X509v3CertificateBuilder cb = new JcaX509v3CertificateBuilder(ca.getSubjectX500Principal(),
BigInteger.valueOf(serialNumberCounter++), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + validity), new X500Principal(cn), pk);
JcaX509ExtensionUtils utils;
utils = new JcaX509ExtensionUtils();
cb.addExtension(Extension.authorityKeyIdentifier, false, utils.createAuthorityKeyIdentifier(ca));
cb.addExtension(Extension.subjectKeyIdentifier, false, utils.createSubjectKeyIdentifier(pk));
cb.addExtension(Extension.basicConstraints, true, new BasicConstraints(false));
cb.addExtension(Extension.keyUsage, true,
new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment));
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(caKey);
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
cert = jX509c.getCertificate(cb.build(signer));
} catch (NoSuchAlgorithmException | CertIOException | OperatorCreationException | CertificateException ex) {
}
return cert;
}
}
| 7,064
| 37.818681
| 115
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/incompleteValidation/src/main/java/icv/incompleteValidation/ValidateCertChainButNoCRL.java
|
package icv.incompleteValidation;
import java.math.BigInteger;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
import java.security.cert.CertPath;
import java.security.cert.CertPathValidator;
import java.security.cert.CertPathValidatorException;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.PKIXCertPathValidatorResult;
import java.security.cert.PKIXParameters;
import java.security.cert.TrustAnchor;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.BasicConstraints;
import org.bouncycastle.asn1.x509.Extension;
import org.bouncycastle.asn1.x509.KeyUsage;
import org.bouncycastle.cert.CertIOException;
import org.bouncycastle.cert.X509v1CertificateBuilder;
import org.bouncycastle.cert.X509v3CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509CertificateConverter;
import org.bouncycastle.cert.jcajce.JcaX509ExtensionUtils;
import org.bouncycastle.cert.jcajce.JcaX509v1CertificateBuilder;
import org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.operator.ContentSigner;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder;
public final class ValidateCertChainButNoCRL {
private static final int oneSecond = 1000;
private static final int oneMinute = oneSecond * 60;
private static final int oneHour = oneMinute * 60;
private static final int oneDay = oneHour * 24;
private static final int oneWeek = oneDay * 7;
private static final int validity = oneWeek;
private static int serialNumberCounter = 1;
public static void main(String[] args) {
Security.addProvider(new BouncyCastleProvider());
try {
List certList = getCertificateList();
CertificateFactory cf = CertificateFactory.getInstance("X.509", "SUN");
CertPath cp = cf.generateCertPath(certList);
TrustAnchor a = new TrustAnchor(rootCA, null);
PKIXParameters params = new PKIXParameters(Collections.singleton(a));
params.setRevocationEnabled(false);
CertPathValidator cpv = CertPathValidator.getInstance("PKIX", "SUN");
PKIXCertPathValidatorResult cpvr = (PKIXCertPathValidatorResult) cpv.validate(cp, params);
} catch (InvalidAlgorithmParameterException | CertPathValidatorException | CertificateException
| NoSuchAlgorithmException e) {
} catch (Exception e) {
}
}
static KeyPair rootKP;
static X509Certificate rootCA;
static List getCertificateList() throws Exception {
getRootCert();
KeyPair mkp1 = genRSAKeyPair();
X509Certificate middle1 = buildMiddleCert(mkp1.getPublic(), "CN=Intermediate CA Certificate",
rootKP.getPrivate(), rootCA);
KeyPair mkp2 = genRSAKeyPair();
X509Certificate middle2 = buildMiddleCert(mkp2.getPublic(), "CN=Intermediate CA Certificate", mkp1.getPrivate(),
middle1);
KeyPair ekp = genRSAKeyPair();
X509Certificate user = buildEndCert(ekp.getPublic(), "CN=End User Certificate", mkp2.getPrivate(), middle2);
Certificate[] certs = new Certificate[] { user, middle2, middle1, rootCA };
List certList = Arrays.asList(certs);
return certList;
}
static X509Certificate getRootCert() throws Exception {
if (rootCA == null) {
rootKP = genRSAKeyPair();
rootCA = buildSelfSignedCert(rootKP);
}
return rootCA;
}
public static KeyPair genRSAKeyPair() throws Exception {
KeyPairGenerator kpGen = KeyPairGenerator.getInstance("RSA", "BC");
kpGen.initialize(2048, new SecureRandom());
return kpGen.generateKeyPair();
}
public static X509Certificate buildMiddleCert(PublicKey pk, String cn, PrivateKey caKey, X509Certificate cac)
throws NoSuchAlgorithmException, CertIOException, OperatorCreationException, CertificateException {
X509Certificate cert = null;
X509v3CertificateBuilder cb = new JcaX509v3CertificateBuilder(cac.getSubjectX500Principal(),
BigInteger.valueOf(serialNumberCounter++), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + validity), new X500Principal(cn), pk);
JcaX509ExtensionUtils utils;
utils = new JcaX509ExtensionUtils();
cb.addExtension(Extension.authorityKeyIdentifier, false, utils.createAuthorityKeyIdentifier(cac));
cb.addExtension(Extension.subjectKeyIdentifier, false, utils.createSubjectKeyIdentifier(pk));
cb.addExtension(Extension.basicConstraints, true, new BasicConstraints(0));
cb.addExtension(Extension.keyUsage, true,
new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyCertSign | KeyUsage.cRLSign));
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(caKey);
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
cert = jX509c.getCertificate(cb.build(signer));
return cert;
}
public static X509Certificate buildEndCert(PublicKey pk, String cn, PrivateKey caKey, X509Certificate ca) {
X509Certificate cert = null;
try {
X509v3CertificateBuilder cb = new JcaX509v3CertificateBuilder(ca.getSubjectX500Principal(),
BigInteger.valueOf(serialNumberCounter++), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + validity), new X500Principal(cn), pk);
JcaX509ExtensionUtils utils;
utils = new JcaX509ExtensionUtils();
cb.addExtension(Extension.authorityKeyIdentifier, false, utils.createAuthorityKeyIdentifier(ca));
cb.addExtension(Extension.subjectKeyIdentifier, false, utils.createSubjectKeyIdentifier(pk));
cb.addExtension(Extension.basicConstraints, true, new BasicConstraints(false));
cb.addExtension(Extension.keyUsage, true,
new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment));
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(caKey);
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
cert = jX509c.getCertificate(cb.build(signer));
} catch (NoSuchAlgorithmException | CertIOException | OperatorCreationException | CertificateException ex) {
}
return cert;
}
public static X509Certificate buildSelfSignedCert(KeyPair keyPair) throws Exception {
X509v1CertificateBuilder certBldr = new JcaX509v1CertificateBuilder(new X500Name("CN=Root Certificate"),
BigInteger.valueOf(1), new Date(System.currentTimeMillis()),
new Date(System.currentTimeMillis() + oneWeek), new X500Name("CN=Root Certificate"),
keyPair.getPublic());
JcaContentSignerBuilder jcsb = new JcaContentSignerBuilder("SHA256withRSA");
jcsb.setProvider("BC");
ContentSigner signer = jcsb.build(keyPair.getPrivate());
JcaX509CertificateConverter jX509c = new JcaX509CertificateConverter();
jX509c.setProvider("BC");
X509Certificate cert = jX509c.getCertificate(certBldr.build(signer));
return cert;
}
}
| 7,451
| 39.064516
| 114
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureComboHashEnc/src/main/java/pdf/insecureComboHashEnc/ManualComboEncryptAndHash.java
|
package pdf.insecureComboHashEnc;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class ManualComboEncryptAndHash {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] iv = new byte[16];
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(256);
Key k = g.generateKey();
(new SecureRandom()).nextBytes(iv);
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
MessageDigest md = MessageDigest.getInstance("SHA256", "BC");
byte[] pt1 = "demo text".getBytes(), X, Y;
boolean ok, ivo = true;
String s = "Encrypt-and-Hash (E&H)";
md.reset();
c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
byte[] ct = c.doFinal(pt1);
byte[] hash = md.digest(pt1);
if (ivo) {
X = "demo text 1".getBytes();
ct = "demo text 2".getBytes();
hash = md.digest("digested text".getBytes());
}
md.reset();
c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
byte[] pt2 = c.doFinal(ct);
ok = MessageDigest.isEqual(md.digest(pt2), hash);
}
}
| 1,353
| 28.434783
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureComboHashEnc/src/main/java/pdf/insecureComboHashEnc/ManualComboEncryptThenHash1.java
|
package pdf.insecureComboHashEnc;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class ManualComboEncryptThenHash1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] iv = new byte[16];
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(256);
Key k = g.generateKey();
(new SecureRandom()).nextBytes(iv);
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
MessageDigest md = MessageDigest.getInstance("SHA256", "BC");
byte[] pt1 = "demo text".getBytes(), X, Y;
boolean ok, ivo = true;
String s = "Encrypt-then-Hash(EtH)";
md.reset();
c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
byte[] ct = c.doFinal(pt1);
byte[] hash = md.digest(ct);
if (ivo) {
X = "demo text 1".getBytes();
ct = "demo text 2".getBytes();
hash = md.digest(ct);
}
ok = MessageDigest.isEqual(md.digest(ct), hash);
if (ok) {
md.reset();
c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
byte[] pt2 = c.doFinal(ct);
}
}
}
| 1,346
| 28.282609
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureComboHashEnc/src/main/java/pdf/insecureComboHashEnc/ManualComboEncryptThenHash2.java
|
package pdf.insecureComboHashEnc;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.Arrays;
public final class ManualComboEncryptThenHash2 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] iv = new byte[16];
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(256);
Key k = g.generateKey();
(new SecureRandom()).nextBytes(iv);
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
MessageDigest md = MessageDigest.getInstance("SHA256", "BC");
byte[] pt1 = "demo text".getBytes(), X, Y;
boolean ok, ivo = true;
String s = "Encrypt-then-Hash(EtH)";
md.reset();
c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
byte[] ct = c.doFinal(pt1);
byte[] ctPlusIV = ct.clone();
Arrays.concatenate(ctPlusIV, iv);
byte[] hash = md.digest(ctPlusIV);
if (ivo) {
X = "demo text 1".getBytes();
ct = "demo text 2".getBytes();
hash = md.digest(ct);
}
md.reset();
c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
byte[] pt2 = c.doFinal(ct);
ctPlusIV = ct.clone();
Arrays.concatenate(ctPlusIV, iv);
ok = MessageDigest.isEqual(md.digest(ctPlusIV), hash);
}
}
| 1,506
| 29.14
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureComboHashEnc/src/main/java/pdf/insecureComboHashEnc/ManualComboHashThenEncrypt.java
|
package pdf.insecureComboHashEnc;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.Arrays;
public final class ManualComboHashThenEncrypt {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] iv = new byte[16];
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(256);
Key k = g.generateKey();
(new SecureRandom()).nextBytes(iv);
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
MessageDigest md = MessageDigest.getInstance("SHA256", "BC");
byte[] pt1 = "demo text".getBytes(), X, Y;
boolean ok, ivo = true;
String s = "Hash-then-Encrypt(HtE)";
md.reset();
c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
byte[] hash = md.digest(pt1);
byte[] concatArrays = Arrays.concatenate(pt1, hash);
byte[] ct = c.doFinal(concatArrays);
if (ivo) {
X = "demo text 2".getBytes();
byte[] cryptoText = Arrays.copyOfRange(ct, 0, 16);
byte[] cryptoTag = Arrays.copyOfRange(ct, 16, ct.length);
md.reset();
byte[] t1 = md.digest("digested1".getBytes());
md.reset();
byte[] t2 = md.digest("digested2".getBytes());
Y = "demo text 3".getBytes();
ct = Arrays.concatenate(cryptoText, cryptoTag);
}
md.reset();
c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
concatArrays = c.doFinal(ct);
byte[] pt2 = Arrays.copyOfRange(concatArrays, 0, 16);
hash = Arrays.copyOfRange(concatArrays, 16, concatArrays.length);
ok = MessageDigest.isEqual(md.digest(pt2), hash);
}
}
| 1,825
| 32.814815
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureComboMacEnc/src/main/java/pdf/insecureComboMacEnc/ManualComboEncryptAndMAC.java
|
package pdf.insecureComboMacEnc;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class ManualComboEncryptAndMAC {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] iv = new byte[16], k2 = new byte[16];
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(256);
Key k1 = g.generateKey();
(new SecureRandom()).nextBytes(iv);
(new SecureRandom()).nextBytes(k2);
SecretKeySpec sks2 = new SecretKeySpec(k2, "HMACSHA256");
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
Mac m = Mac.getInstance("HMACSHA256", "BC");
byte[] pt1 = "demo text".getBytes(), X;
boolean ok, ivo = false;
String s = "Encrypt-and-MAC (E&M)";
m.init(sks2);
c.init(Cipher.ENCRYPT_MODE, k1, new IvParameterSpec(iv));
byte[] ct = c.doFinal(pt1);
byte[] tag = m.doFinal(pt1);
if (ivo) {
X = "demo text 1".getBytes();
ct = "demo text 2".getBytes();
}
m.init(sks2);
c.init(Cipher.DECRYPT_MODE, k1, new IvParameterSpec(iv));
byte[] pt2 = c.doFinal(ct);
ok = MessageDigest.isEqual(m.doFinal(pt2), tag);
}
}
| 1,442
| 30.369565
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureComboMacEnc/src/main/java/pdf/insecureComboMacEnc/ManualComboEncryptThenMAC1.java
|
package pdf.insecureComboMacEnc;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class ManualComboEncryptThenMAC1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] iv = new byte[16], k2 = new byte[16];
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(256);
Key k1 = g.generateKey();
(new SecureRandom()).nextBytes(iv);
(new SecureRandom()).nextBytes(k2);
SecretKeySpec sks2 = new SecretKeySpec(k2, "HMACSHA256");
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
Mac m = Mac.getInstance("HMACSHA256", "BC");
byte[] text1 = "demo text".getBytes(), X;
boolean ok, ivo = false;
String s = "Encrypt-then-MAC(EtM)";
m.init(sks2);
c.init(Cipher.ENCRYPT_MODE, k1, new IvParameterSpec(iv));
byte[] ciphered = c.doFinal(text1);
byte[] tag = m.doFinal(ciphered);
if (ivo) {
X = "demo text 1".getBytes();
ciphered = "demo text 2".getBytes();
}
ok = MessageDigest.isEqual(m.doFinal(ciphered), tag);
if (ok) {
m.init(sks2);
c.init(Cipher.DECRYPT_MODE, k1, new IvParameterSpec(iv));
byte[] textoclaroBeto = c.doFinal(ciphered);
}
}
}
| 1,506
| 30.395833
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureComboMacEnc/src/main/java/pdf/insecureComboMacEnc/ManualComboEncryptThenMAC2.java
|
package pdf.insecureComboMacEnc;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.Arrays;
public final class ManualComboEncryptThenMAC2 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] iv = new byte[16], k2 = new byte[16];
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(256);
Key k1 = g.generateKey();
(new SecureRandom()).nextBytes(iv);
(new SecureRandom()).nextBytes(k2);
SecretKeySpec sks2 = new SecretKeySpec(k2, "HMACSHA256");
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
Mac m = Mac.getInstance("HMACSHA256", "BC");
byte[] pt1 = "demo text".getBytes(), X;
boolean ok, ivo = false;
String s = "Encrypt-then-MAC(EtM)";
m.init(sks2);
c.init(Cipher.ENCRYPT_MODE, k1, new IvParameterSpec(iv));
byte[] ct = c.doFinal(pt1);
byte[] ctPlusIV = ct.clone();
Arrays.concatenate(ctPlusIV, iv);
byte[] tag = m.doFinal(ctPlusIV);
m.init(sks2);
c.init(Cipher.DECRYPT_MODE, k1, new IvParameterSpec(iv));
byte[] pt2 = c.doFinal(ct);
ctPlusIV = ct.clone();
Arrays.concatenate(ctPlusIV, iv);
ok = MessageDigest.isEqual(m.doFinal(ctPlusIV), tag);
}
}
| 1,536
| 31.702128
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureComboMacEnc/src/main/java/pdf/insecureComboMacEnc/ManualComboMACThenEncrypt.java
|
package pdf.insecureComboMacEnc;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.Arrays;
public final class ManualComboMACThenEncrypt {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] iv = new byte[16], k2 = new byte[16];
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(256);
Key k1 = g.generateKey();
(new SecureRandom()).nextBytes(iv);
(new SecureRandom()).nextBytes(k2);
SecretKeySpec sks2 = new SecretKeySpec(k2, "HMACSHA256");
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
Mac m = Mac.getInstance("HMACSHA256", "BC");
byte[] pt1 = "demo text".getBytes(), X;
boolean ok, ivo = false;
String s = "MAC-then-Encrypt (MtE)";
m.init(sks2);
c.init(Cipher.ENCRYPT_MODE, k1, new IvParameterSpec(iv));
byte[] tag = m.doFinal(pt1);
byte[] pack = Arrays.concatenate(pt1, tag);
byte[] ct = c.doFinal(pack);
m.init(sks2);
c.init(Cipher.DECRYPT_MODE, k1, new IvParameterSpec(iv));
pack = c.doFinal(ct);
byte[] ptBeto = Arrays.copyOfRange(pack, 0, 16);
tag = Arrays.copyOfRange(pack, 16, pack.length);
ok = MessageDigest.isEqual(m.doFinal(ptBeto), tag);
}
}
| 1,543
| 32.565217
| 101
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureDefault/src/main/java/pdf/insecureDefault/InsecureDefault3DES.java
|
package pdf.insecureDefault;
import javax.crypto.*;
import java.security.*;
public final class InsecureDefault3DES {
public static void main(String args[]) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException, NoSuchProviderException {
byte[] msg = "demo msg".getBytes();
KeyGenerator kg = KeyGenerator.getInstance("DESede", "SunJCE");
kg.init(168);
Key key = kg.generateKey();
Cipher ciph = Cipher.getInstance("DESede", "SunJCE");
ciph.init(Cipher.ENCRYPT_MODE, key);
byte[] ciphered = ciph.doFinal(msg);
ciph.init(Cipher.DECRYPT_MODE, key);
byte[] deciphered = ciph.doFinal(ciphered);
}
}
| 690
| 30.409091
| 117
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureDefault/src/main/java/pdf/insecureDefault/InsecureDefaultAES.java
|
package pdf.insecureDefault;
import javax.crypto.*;
import java.security.*;
public final class InsecureDefaultAES {
public static void main(String args[]) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException, NoSuchProviderException {
byte[] msg = "demo msg".getBytes();
KeyGenerator kg = KeyGenerator.getInstance("AES", "SunJCE");
kg.init(256);
Key key = kg.generateKey();
Cipher ciph = Cipher.getInstance("AES", "SunJCE");
ciph.init(Cipher.ENCRYPT_MODE, key);
byte[] ciphered = ciph.doFinal(msg);
ciph.init(Cipher.DECRYPT_MODE, key);
byte[] deciphered = ciph.doFinal(ciphered);
}
}
| 682
| 31.52381
| 117
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureDefault/src/main/java/pdf/insecureDefault/InsecureDefaultOAEP.java
|
package pdf.insecureDefault;
import javax.crypto.*;
import java.security.*;
import java.security.spec.*;
import javax.crypto.spec.*;
import javax.crypto.spec.PSource;
import org.bouncycastle.jce.provider.*;
public final class InsecureDefaultOAEP {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 384;
int hsize = 160;
String rsaName = "RSA/None/OAEPPadding";
int maxLenBytes = (ksize - 2 * hsize) / 8 - 2;
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(ksize);
KeyPair kp = kpg.generateKeyPair();
MGF1ParameterSpec mgf1ps = MGF1ParameterSpec.SHA1;
OAEPParameterSpec OAEPps = new OAEPParameterSpec("SHA1", "MGF1", mgf1ps, PSource.PSpecified.DEFAULT);
Cipher c = Cipher.getInstance(rsaName, "BC");
c.init(Cipher.ENCRYPT_MODE, kp.getPublic(), OAEPps);
byte[] pt1 = "This is a demo text".substring(0, maxLenBytes).getBytes();
byte[] ct = c.doFinal(pt1);
c.init(Cipher.DECRYPT_MODE, kp.getPrivate(), OAEPps);
byte[] pt2 = c.doFinal(ct);
}
}
| 1,262
| 29.804878
| 103
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureDefault/src/main/java/pdf/insecureDefault/InsecureDefaultPBE.java
|
package pdf.insecureDefault;
import javax.crypto.*;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.spec.PBEKeySpec;
import org.bouncycastle.jce.provider.*;
//
public final class InsecureDefaultPBE {
@SuppressWarnings("empty-statement")
public static void main(String args[]) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException, NoSuchProviderException, InvalidKeySpecException,
InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
if (args != null) {
char[] password = args[0].toCharArray();
byte[] salt = new byte[16];
(new SecureRandom()).nextBytes(salt);
int iterationCount = 2048;
PBEKeySpec pbeks = new PBEKeySpec(password, salt, iterationCount);
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBE", "SunJCE");
Key sk = skf.generateSecret(pbeks);
}
}
}
| 964
| 28.242424
| 117
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureDefault/src/main/java/pdf/insecureDefault/InsecureDefaultPRNG.java
|
package pdf.insecureDefault;
import java.security.SecureRandom;
public final class InsecureDefaultPRNG {
public static void main(String[] args) {
try {
SecureRandom r1 = new SecureRandom();
SecureRandom r2 = new SecureRandom();
} catch (Exception e) {
}
}
}
| 277
| 15.352941
| 41
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureDefault/src/main/java/pdf/insecureDefault/InsecureDefaultRSA.java
|
package pdf.insecureDefault;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class InsecureDefaultRSA {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[] msg1 = ("Insecure default RSA.").getBytes();
KeyPairGenerator g = KeyPairGenerator.getInstance("RSA", "BC");
g.initialize(2048);
KeyPair kp = g.generateKeyPair();
Cipher enc = Cipher.getInstance("RSA", "BC");
enc.init(Cipher.ENCRYPT_MODE, kp.getPublic());
Cipher dec = Cipher.getInstance("RSA", "BC");
dec.init(Cipher.DECRYPT_MODE, kp.getPrivate());
byte[][] ct = new byte[2][];
for (int i = 0; i < 2; i++) {
ct[i] = enc.doFinal(msg1);
byte[] pt2 = dec.doFinal(ct[i]);
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException
| BadPaddingException | NoSuchProviderException e) {
}
}
}
| 1,328
| 31.414634
| 110
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurePadding/src/main/java/pkc/enc/insecurePadding/InsecurePaddingRSA1.java
|
package pkc.enc.insecurePadding;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class InsecurePaddingRSA1 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[] msg1 = ("demo msg").getBytes();
KeyPairGenerator g = KeyPairGenerator.getInstance("RSA", "BC");
g.initialize(2048);
KeyPair kp = g.generateKeyPair();
Cipher enc = Cipher.getInstance("RSA/ECB/NoPadding", "BC");
enc.init(Cipher.ENCRYPT_MODE, kp.getPublic());
Cipher dec = Cipher.getInstance("RSA/ECB/NoPadding", "BC");
dec.init(Cipher.DECRYPT_MODE, kp.getPrivate());
byte[][] ct = new byte[2][];
for (int i = 0; i < 2; i++) {
ct[i] = enc.doFinal(msg1);
byte[] deciphered = dec.doFinal(ct[i]);
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException
| BadPaddingException | NoSuchProviderException e) {
}
}
}
| 1,355
| 32.073171
| 110
|
java
|
CryptoAnalysis
|
CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurePadding/src/main/java/pkc/enc/insecurePadding/InsecurePaddingRSA2.java
|
package pkc.enc.insecurePadding;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.Security;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class InsecurePaddingRSA2 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[] msg1 = ("demo msg").getBytes();
KeyPairGenerator g = KeyPairGenerator.getInstance("RSA", "BC");
g.initialize(2048);
KeyPair kp = g.generateKeyPair();
Cipher enc = Cipher.getInstance("RSA/None/NoPadding", "BC");
enc.init(Cipher.ENCRYPT_MODE, kp.getPublic());
Cipher dec = Cipher.getInstance("RSA/None/NoPadding", "BC");
dec.init(Cipher.DECRYPT_MODE, kp.getPrivate());
byte[][] ct = new byte[2][];
for (int i = 0; i < 2; i++) {
ct[i] = enc.doFinal(msg1);
byte[] deciphered = dec.doFinal(ct[i]);
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException
| BadPaddingException | NoSuchProviderException e) {
}
}
}
| 1,357
| 32.121951
| 110
|
java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.