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/cryptomisuses/insecurePadding/src/main/java/pkc/enc/insecurePadding/InsecurePaddingRSA3.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 InsecurePaddingRSA3 {
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 |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurePaddingSign/src/main/java/pkc/sign/insecurePaddingSign/PKCS1Signature.java | package pkc.sign.insecurePaddingSign;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.security.Signature;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class PKCS1Signature {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kg = KeyPairGenerator.getInstance("RSA", "BC");
kg.initialize(2048, new SecureRandom());
KeyPair kp = kg.generateKeyPair();
Signature sig = Signature.getInstance("SHA1withRSA", "BC");
byte[] m = "Testing RSA PKCS1".getBytes("UTF-8");
sig.initSign(kp.getPrivate(), new SecureRandom());
sig.update(m);
byte[] s = sig.sign();
sig.initVerify(kp.getPublic());
sig.update(m);
}
}
| 832 | 25.03125 | 66 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurePaddingSign/src/main/java/pkc/sign/insecurePaddingSign/PKCS1Signature1.java | package pkc.sign.insecurePaddingSign;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.security.Signature;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class PKCS1Signature1 {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kg = KeyPairGenerator.getInstance("RSA", "BC");
kg.initialize(2048, new SecureRandom());
KeyPair kp = kg.generateKeyPair();
Signature sig = Signature.getInstance("SHA256withRSA", "BC");
byte[] m = "Testing RSA PKCS1".getBytes("UTF-8");
sig.initSign(kp.getPrivate(), new SecureRandom());
sig.update(m);
byte[] s = sig.sign();
sig.initVerify(kp.getPublic());
sig.update(m);
}
}
| 835 | 25.125 | 66 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurePaddingSign/src/main/java/pkc/sign/insecurePaddingSign/PKCS1Signature2.java | package pkc.sign.insecurePaddingSign;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.security.Signature;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class PKCS1Signature2 {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kg = KeyPairGenerator.getInstance("RSA", "BC");
kg.initialize(2048, new SecureRandom());
KeyPair kp = kg.generateKeyPair();
Signature sig = Signature.getInstance("SHA512withRSA", "BC");
byte[] m = "Testing RSA PKCS1".getBytes("UTF-8");
sig.initSign(kp.getPrivate(), new SecureRandom());
sig.update(m);
byte[] s = sig.sign();
sig.initVerify(kp.getPublic());
sig.update(m);
}
}
| 835 | 25.125 | 66 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurePaddingSign/src/main/java/pkc/sign/insecurePaddingSign/PSSwSHA1Signature.java | package pkc.sign.insecurePaddingSign;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.security.Signature;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class PSSwSHA1Signature {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kg = KeyPairGenerator.getInstance("RSA", "BC");
kg.initialize(2048, new SecureRandom());
KeyPair kp = kg.generateKeyPair();
Signature sig = Signature.getInstance("SHA1withRSAandMGF1", "BC");
byte[] m = "Testing RSA PSS w/ SHA1".getBytes("UTF-8");
sig.initSign(kp.getPrivate(), new SecureRandom());
sig.update(m);
byte[] s = sig.sign();
sig.initVerify(kp.getPublic());
sig.update(m);
}
}
| 848 | 25.53125 | 68 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurePaddingSign/src/main/java/pkc/sign/insecurePaddingSign/PSSwSHA1Signature1.java | package pkc.sign.insecurePaddingSign;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.security.Signature;
import java.security.spec.PSSParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class PSSwSHA1Signature1 {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kg = KeyPairGenerator.getInstance("RSA", "BC");
kg.initialize(2048, new SecureRandom());
KeyPair kp = kg.generateKeyPair();
Signature sig = Signature.getInstance("SHA1withRSAandMGF1", "BC");
sig.setParameter(PSSParameterSpec.DEFAULT);
byte[] m = "Testing RSA PSS w/ SHA1".getBytes("UTF-8");
sig.initSign(kp.getPrivate(), new SecureRandom());
sig.update(m);
byte[] s = sig.sign();
sig.initVerify(kp.getPublic());
sig.update(m);
}
}
| 939 | 26.647059 | 68 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurePaddingSign/src/main/java/pkc/sign/insecurePaddingSign/PSSwSHA1Signature2.java | package pkc.sign.insecurePaddingSign;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.security.Signature;
import java.security.spec.MGF1ParameterSpec;
import java.security.spec.PSSParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class PSSwSHA1Signature2 {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kg = KeyPairGenerator.getInstance("RSA", "BC");
kg.initialize(2048, new SecureRandom());
KeyPair kp = kg.generateKeyPair();
Signature sig = Signature.getInstance("SHA1withRSAandMGF1", "BC");
PSSParameterSpec spec = new PSSParameterSpec("SHA-1", "MGF1", MGF1ParameterSpec.SHA1, 20, 1);
sig.setParameter(spec);
byte[] m = "Testing RSA PSS w/ SHA1".getBytes("UTF-8");
sig.initSign(kp.getPrivate(), new SecureRandom());
sig.update(m);
byte[] s = sig.sign();
sig.initVerify(kp.getPublic());
sig.update(m);
}
}
| 1,060 | 28.472222 | 95 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureStreamCipher/src/main/java/pdf/insecureStreamCipher/ConfusingBlockAndStream.java | package pdf.insecureStreamCipher;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class ConfusingBlockAndStream {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[][] M = { ("msg1").getBytes(), ("msg2").getBytes() };
byte[][] C = new byte[2][], iv = new byte[2][];
byte[] k = "00112233445566778899AABBCCDDEEFF".getBytes();
byte[] seed = "0123456789ABCDEF0123456789ABCDEF".getBytes();
SecretKeySpec ks = new SecretKeySpec(k, "AES");
Cipher enc = Cipher.getInstance("AES/OFB/NoPadding", "BC");
SecureRandom sr = new SecureRandom();
sr.setSeed(seed);
enc.init(Cipher.ENCRYPT_MODE, ks, sr);
C[0] = enc.doFinal(M[0]);
iv[0] = enc.getIV();
sr = new SecureRandom();
sr.setSeed(seed);
enc.init(Cipher.ENCRYPT_MODE, ks, sr);
C[1] = enc.doFinal(M[1]);
iv[1] = enc.getIV();
} catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException ex) {
} catch (InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) {
}
}
}
| 1,166 | 28.923077 | 92 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecureStreamCipher/src/main/java/pdf/insecureStreamCipher/MalealableStreamCipher.java | package pdf.insecureStreamCipher;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class MalealableStreamCipher {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[][] M = { ("msg1").getBytes(), ("msg2").getBytes() };
byte[][] iv = { "0123456789ABCDEF0123456789ABCDEF".getBytes(),
"0123456789ABCDEF0123456789ABCDEF".getBytes() };
byte[][] iv2 = { iv[0].clone(), iv[0].clone() };
byte[] k = "00112233445566778899AABBCCDDEEFF".getBytes(), X = null;
byte[][] C = new byte[2][], N = new byte[2][];
SecretKeySpec ks = new SecretKeySpec(k, "AES");
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
for (int i = 0; i < M.length; i++) {
c.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv[i]));
C[i] = c.doFinal(M[i]);
}
for (int i = 0; i < C.length; i++) {
c.init(Cipher.DECRYPT_MODE, ks, new IvParameterSpec(iv2[i]));
N[i] = c.doFinal(C[i]);
}
} catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | InvalidKeyException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
}
}
}
| 1,280 | 33.621622 | 108 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurecurves/src/main/java/pkc/ecc/insecurecurves/InsecureCurveECDH1.java | package pkc.ecc.insecurecurves;
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 InsecureCurveECDH1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp112r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 705 | 29.695652 | 103 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurecurves/src/main/java/pkc/ecc/insecurecurves/InsecureCurve_secp112r1.java | package pkc.ecc.insecurecurves;
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 InsecureCurve_secp112r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp112r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 710 | 29.913043 | 103 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurecurves/src/main/java/pkc/ecc/insecurecurves/InsecureCurve_secp128r1.java | package pkc.ecc.insecurecurves;
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 InsecureCurve_secp128r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp128r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 710 | 29.913043 | 103 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurecurves/src/main/java/pkc/ecc/insecurecurves/InsecureCurve_secp160k1.java | package pkc.ecc.insecurecurves;
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 InsecureCurve_secp160k1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp160k1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 710 | 29.913043 | 103 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurecurves/src/main/java/pkc/ecc/insecurecurves/InsecureCurve_secp160r1.java | package pkc.ecc.insecurecurves;
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 InsecureCurve_secp160r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp160r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 710 | 29.913043 | 103 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurecurves/src/main/java/pkc/ecc/insecurecurves/InsecureCurve_sect113r1.java | package pkc.ecc.insecurecurves;
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 InsecureCurve_sect113r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect113r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 710 | 29.913043 | 103 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurecurves/src/main/java/pkc/ecc/insecurecurves/InsecureCurve_sect131r1.java | package pkc.ecc.insecurecurves;
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 InsecureCurve_sect131r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect131r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 710 | 29.913043 | 103 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/insecurecurves/src/main/java/pkc/ecc/insecurecurves/InsecureCurve_sect193r1.java | package pkc.ecc.insecurecurves;
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 InsecureCurve_sect193r1 {
public static void main(String argv[]) {
try {
ECGenParameterSpec ecps = new ECGenParameterSpec("sect193r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
} catch (NoSuchAlgorithmException | InvalidAlgorithmParameterException | NoSuchProviderException e) {
}
}
}
| 710 | 29.913043 | 103 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/issuesDHandECDH/src/main/java/pkc/ka/issuesDHandECDH/NonAuthenticatedDH_1024.java | package pkc.ka.issuesDHandECDH;
import java.security.*;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
public final class NonAuthenticatedDH_1024 {
public static void main(String argv[]) {
try {
AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance("DH", "SunJCE");
apg.init(1024);
AlgorithmParameters p = apg.generateParameters();
DHParameterSpec dhps = (DHParameterSpec) p.getParameterSpec(DHParameterSpec.class);
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("DH", "SunJCE");
kpg1.initialize(dhps);
KeyPair kp1 = kpg1.generateKeyPair();
KeyAgreement ka1 = KeyAgreement.getInstance("DH", "SunJCE");
ka1.init(kp1.getPrivate());
byte[] pubKey1 = kp1.getPublic().getEncoded();
KeyFactory kf1 = KeyFactory.getInstance("DH", "SunJCE");
X509EncodedKeySpec x509ks = new X509EncodedKeySpec(pubKey1);
PublicKey apk1 = kf1.generatePublic(x509ks);
DHParameterSpec dhps2 = ((DHPublicKey) apk1).getParams();
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance("DH", "SunJCE");
kpg2.initialize(dhps2);
KeyPair kp2 = kpg2.generateKeyPair();
KeyAgreement ka2 = KeyAgreement.getInstance("DH", "SunJCE");
ka2.init(kp2.getPrivate());
byte[] pubKey2 = kp2.getPublic().getEncoded();
KeyFactory kf2 = KeyFactory.getInstance("DH", "SunJCE");
x509ks = new X509EncodedKeySpec(pubKey2);
PublicKey apk2 = kf2.generatePublic(x509ks);
ka1.doPhase(apk2, true);
byte[] genSec1 = ka1.generateSecret();
ka2.doPhase(apk1, true);
byte[] genSec2 = ka2.generateSecret();
} catch (Exception e) {
}
}
}
| 1,664 | 29.272727 | 93 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/issuesDHandECDH/src/main/java/pkc/ka/issuesDHandECDH/NonAuthenticatedDH_512.java | package pkc.ka.issuesDHandECDH;
import java.security.*;
import java.security.spec.*;
import java.util.Arrays;
import javax.crypto.*;
import javax.crypto.spec.*;
import javax.crypto.interfaces.*;
public final class NonAuthenticatedDH_512 {
public static void main(String argv[]) {
try {
AlgorithmParameterGenerator apg = AlgorithmParameterGenerator.getInstance("DH", "SunJCE");
apg.init(512);
AlgorithmParameters p = apg.generateParameters();
DHParameterSpec dhps = (DHParameterSpec) p.getParameterSpec(DHParameterSpec.class);
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("DH", "SunJCE");
kpg1.initialize(dhps);
KeyPair kp1 = kpg1.generateKeyPair();
KeyAgreement ka1 = KeyAgreement.getInstance("DH", "SunJCE");
ka1.init(kp1.getPrivate());
byte[] pubKey1 = kp1.getPublic().getEncoded();
KeyFactory kf1 = KeyFactory.getInstance("DH", "SunJCE");
X509EncodedKeySpec x509ks = new X509EncodedKeySpec(pubKey1);
PublicKey apk1 = kf1.generatePublic(x509ks);
DHParameterSpec dhps2 = ((DHPublicKey) apk1).getParams();
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance("DH", "SunJCE");
kpg2.initialize(dhps2);
KeyPair kp2 = kpg2.generateKeyPair();
KeyAgreement ka2 = KeyAgreement.getInstance("DH", "SunJCE");
ka2.init(kp2.getPrivate());
byte[] pubKey2 = kp2.getPublic().getEncoded();
KeyFactory kf2 = KeyFactory.getInstance("DH", "SunJCE");
x509ks = new X509EncodedKeySpec(pubKey2);
PublicKey apk2 = kf2.generatePublic(x509ks);
ka1.doPhase(apk2, true);
byte[] genSec1 = ka1.generateSecret();
ka2.doPhase(apk1, true);
byte[] genSec2 = ka2.generateSecret();
if (!Arrays.equals(genSec1, genSec2)) {
throw new Exception("Shared secrets differ");
}
} catch (Exception e) {
}
}
}
| 1,783 | 30.298246 | 93 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/issuesDHandECDH/src/main/java/pkc/ka/issuesDHandECDH/NonAuthenticatedEphemeralDH_1024.java | package pkc.ka.issuesDHandECDH;
import java.security.*;
import java.security.spec.*;
import java.util.Arrays;
import javax.crypto.*;
public final class NonAuthenticatedEphemeralDH_1024 {
public static void main(String argv[]) {
try {
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("DH", "SunJCE");
kpg1.initialize(1024);
KeyPair kp1 = kpg1.generateKeyPair();
KeyAgreement ka1 = KeyAgreement.getInstance("DH", "SunJCE");
ka1.init(kp1.getPrivate());
byte[] pubKey1 = kp1.getPublic().getEncoded();
KeyFactory kf1 = KeyFactory.getInstance("DH", "SunJCE");
X509EncodedKeySpec x509ks = new X509EncodedKeySpec(pubKey1);
PublicKey apk1 = kf1.generatePublic(x509ks);
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance("DH", "SunJCE");
kpg2.initialize(1024);
KeyPair kp2 = kpg2.generateKeyPair();
KeyAgreement ka2 = KeyAgreement.getInstance("DH", "SunJCE");
ka2.init(kp2.getPrivate());
byte[] pubKey2 = kp2.getPublic().getEncoded();
KeyFactory kf2 = KeyFactory.getInstance("DH", "SunJCE");
x509ks = new X509EncodedKeySpec(pubKey2);
PublicKey apk2 = kf2.generatePublic(x509ks);
ka1.doPhase(apk2, true);
byte[] genSec1 = ka1.generateSecret();
ka2.doPhase(apk1, true);
byte[] genSec2 = ka2.generateSecret();
if (!Arrays.equals(genSec1, genSec2)) {
throw new Exception("Shared secrets differ");
}
} catch (Exception e) {
}
}
}
| 1,415 | 28.5 | 72 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/issuesDHandECDH/src/main/java/pkc/ka/issuesDHandECDH/NonAuthenticatedEphemeralDH_512.java | package pkc.ka.issuesDHandECDH;
import java.security.*;
import java.security.spec.*;
import java.util.Arrays;
import javax.crypto.*;
public final class NonAuthenticatedEphemeralDH_512 {
public static void main(String argv[]) {
try {
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("DH", "SunJCE");
kpg1.initialize(512);
KeyPair kp1 = kpg1.generateKeyPair();
KeyAgreement ka1 = KeyAgreement.getInstance("DH", "SunJCE");
ka1.init(kp1.getPrivate());
byte[] pubKey1 = kp1.getPublic().getEncoded();
KeyFactory kf1 = KeyFactory.getInstance("DH", "SunJCE");
X509EncodedKeySpec x509ks = new X509EncodedKeySpec(pubKey1);
PublicKey apk1 = kf1.generatePublic(x509ks);
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance("DH", "SunJCE");
kpg2.initialize(512);
KeyPair kp2 = kpg2.generateKeyPair();
KeyAgreement ka2 = KeyAgreement.getInstance("DH", "SunJCE");
ka2.init(kp2.getPrivate());
byte[] pubKey2 = kp2.getPublic().getEncoded();
KeyFactory kf2 = KeyFactory.getInstance("DH", "SunJCE");
x509ks = new X509EncodedKeySpec(pubKey2);
PublicKey apk2 = kf2.generatePublic(x509ks);
ka1.doPhase(apk2, true);
byte[] genSec1 = ka1.generateSecret();
ka2.doPhase(apk1, true);
byte[] genSec2 = ka2.generateSecret();
if (!Arrays.equals(genSec1, genSec2)) {
throw new Exception("Shared secrets differ");
}
} catch (Exception e) {
}
}
}
| 1,413 | 27.857143 | 72 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/issuesDHandECDH/src/main/java/pkc/ka/issuesDHandECDH/NonAuthenticatedEphemeralECDH_112.java | package pkc.ka.issuesDHandECDH;
import java.security.*;
import java.security.spec.*;
import java.util.Arrays;
import javax.crypto.*;
public final class NonAuthenticatedEphemeralECDH_112 {
public static void main(String argv[]) {
try {
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("EC", "SunEC");
kpg1.initialize(224);
KeyPair kp1 = kpg1.generateKeyPair();
KeyAgreement ka1 = KeyAgreement.getInstance("ECDH", "SunEC");
ka1.init(kp1.getPrivate());
byte[] pubKey1 = kp1.getPublic().getEncoded();
KeyFactory kf1 = KeyFactory.getInstance("EC", "SunEC");
X509EncodedKeySpec x509ks = new X509EncodedKeySpec(pubKey1);
PublicKey apk1 = kf1.generatePublic(x509ks);
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance("EC", "SunEC");
kpg2.initialize(224);
KeyPair kp2 = kpg2.generateKeyPair();
KeyAgreement ka2 = KeyAgreement.getInstance("ECDH", "SunEC");
ka2.init(kp2.getPrivate());
byte[] pubKey2 = kp2.getPublic().getEncoded();
KeyFactory kf2 = KeyFactory.getInstance("EC", "SunEC");
x509ks = new X509EncodedKeySpec(pubKey2);
PublicKey apk2 = kf2.generatePublic(x509ks);
ka1.doPhase(apk2, true);
byte[] genSec1 = ka1.generateSecret();
ka2.doPhase(apk1, true);
byte[] genSec2 = ka2.generateSecret();
if (!Arrays.equals(genSec1, genSec2)) {
throw new Exception("Shared secrets differ");
}
} catch (Exception e) {
}
}
}
| 1,413 | 27.857143 | 71 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/issuesDHandECDH/src/main/java/pkc/ka/issuesDHandECDH/NonAuthenticatedEphemeralECDH_80.java | package pkc.ka.issuesDHandECDH;
import java.security.*;
import java.security.spec.*;
import java.util.Arrays;
import javax.crypto.*;
public final class NonAuthenticatedEphemeralECDH_80 {
public static void main(String argv[]) {
try {
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("EC", "SunEC");
kpg1.initialize(160); // this has only 112 bits of security
KeyPair kp1 = kpg1.generateKeyPair();
KeyAgreement ka1 = KeyAgreement.getInstance("ECDH", "SunEC");
ka1.init(kp1.getPrivate());
byte[] pubKey1 = kp1.getPublic().getEncoded();
KeyFactory kf1 = KeyFactory.getInstance("EC", "SunEC");
X509EncodedKeySpec x509ks = new X509EncodedKeySpec(pubKey1);
PublicKey apk1 = kf1.generatePublic(x509ks);
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance("EC", "SunEC");
kpg2.initialize(160);
KeyPair kp2 = kpg2.generateKeyPair();
KeyAgreement ka2 = KeyAgreement.getInstance("ECDH", "SunEC");
ka2.init(kp2.getPrivate());
byte[] pubKey2 = kp2.getPublic().getEncoded();
KeyFactory kf2 = KeyFactory.getInstance("EC", "SunEC");
x509ks = new X509EncodedKeySpec(pubKey2);
PublicKey apk2 = kf2.generatePublic(x509ks);
ka1.doPhase(apk2, true);
byte[] genSec1 = ka1.generateSecret();
ka2.doPhase(apk1, true);
byte[] genSec2 = ka2.generateSecret();
if (!Arrays.equals(genSec1, genSec2)) {
throw new Exception("Shared secrets differ");
}
} catch (Exception e) {
}
}
}
| 1,446 | 31.155556 | 71 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/keyReuseInStreamCipher/src/main/java/pkm/keyReuseInStreamCipher/KeyReuseStreamCipher1.java | package pkm.keyReuseInStreamCipher;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
//
public final class KeyReuseStreamCipher1 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[][] M = { ("key1").getBytes(), ("key2").getBytes() };
byte[][] iv = { "0123456789ABCDEF0123456789ABCDEF".getBytes(),
"0123456789ABCDEF0123456789ABCDEF".getBytes() };
byte[] k = "00112233445566778899AABBCCDDEEFF".getBytes();
byte[][] C = new byte[2][];
SecretKeySpec ks = new SecretKeySpec(k, "AES");
Cipher enc = Cipher.getInstance("AES/OFB/NoPadding", "BC");
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv[0]));
C[0] = enc.doFinal(M[0]);
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv[1]));
C[1] = enc.doFinal(M[1]);
} catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | InvalidKeyException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
}
}
}
| 1,118 | 32.909091 | 108 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/keyReuseInStreamCipher/src/main/java/pkm/keyReuseInStreamCipher/KeyReuseStreamCipher2.java |
package pkm.keyReuseInStreamCipher;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class KeyReuseStreamCipher2 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[][] M = { ("key1").getBytes(), ("key2").getBytes() };
byte[][] iv = { "0123456789ABCDEF0123456789ABCDEF".getBytes(),
"0123456789ABCDEF0123456789ABCDEF".getBytes() };
byte[] k = new byte[16];
(new SecureRandom()).nextBytes(k);
byte[][] C = new byte[2][];
SecretKeySpec ks = new SecretKeySpec(k, "AES");
Cipher enc = Cipher.getInstance("AES/OFB/NoPadding", "BC");
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv[0]));
C[0] = enc.doFinal(M[0]);
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv[1]));
C[1] = enc.doFinal(M[1]);
} catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | InvalidKeyException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
}
}
}
| 1,121 | 32 | 108 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/keyReuseInStreamCipher/src/main/java/pkm/keyReuseInStreamCipher/KeyReuseStreamCipher3.java |
package pkm.keyReuseInStreamCipher;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class KeyReuseStreamCipher3 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[][] M = { ("key1").getBytes(), ("key2").getBytes() };
byte[] iv1 = 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 };
byte[] iv2 = 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 };
byte[] k = new byte[16];
(new SecureRandom()).nextBytes(k);
byte[][] C = new byte[2][];
SecretKeySpec ks = new SecretKeySpec(k, "AES");
Cipher enc = Cipher.getInstance("AES/OFB/NoPadding", "BC");
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv1));
C[0] = enc.doFinal(M[0]);
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv2));
C[1] = enc.doFinal(M[1]);
} catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | InvalidKeyException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
}
}
}
| 1,496 | 37.384615 | 108 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/keyReuseInStreamCipher/src/main/java/pkm/keyReuseInStreamCipher/KeyReuseStreamCipher4.java |
package pkm.keyReuseInStreamCipher;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class KeyReuseStreamCipher4 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[][] M = { ("key1").getBytes(), ("key2").getBytes() };
byte[] seed = 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 };
SecureRandom sr = new SecureRandom();
sr.setSeed(seed);
byte[] iv = new byte[16];
byte[] k = new byte[16];
sr.nextBytes(k);
sr.nextBytes(iv);
byte[][] C = new byte[2][];
SecretKeySpec ks = new SecretKeySpec(k, "AES");
Cipher enc = Cipher.getInstance("AES/OFB/NoPadding", "BC");
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv));
C[0] = enc.doFinal(M[0]);
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv));
C[1] = enc.doFinal(M[1]);
} catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | InvalidKeyException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
}
}
}
| 1,343 | 30.255814 | 108 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/keyReuseInStreamCipher/src/main/java/pkm/keyReuseInStreamCipher/KeyReuseStreamCipher5.java |
package pkm.keyReuseInStreamCipher;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
//
public final class KeyReuseStreamCipher5 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[][] M = { ("key1").getBytes(), ("key2").getBytes() };
SecureRandom sr = new SecureRandom();
byte[] iv = new byte[16], k = new byte[16];
sr.nextBytes(k);
sr.nextBytes(iv);
byte[][] C = new byte[2][];
SecretKeySpec ks = new SecretKeySpec(k, "AES");
Cipher enc = Cipher.getInstance("AES/OFB/NoPadding", "BC");
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv));
C[0] = enc.doFinal(M[0]);
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv));
C[1] = enc.doFinal(M[1]);
} catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | InvalidKeyException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
}
}
}
| 1,065 | 26.333333 | 108 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/nonceReuse/src/main/java/ivm/nonceReuse/NonceReuse1.java |
package ivm.nonceReuse;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
//
public final class NonceReuse1 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[][] M = { ("Hidden part.....").getBytes(), ("Revealed part...").getBytes() };
SecureRandom sr = SecureRandom.getInstanceStrong();
byte[] iv = new byte[16], k = new byte[16];
byte[][] C = new byte[2][];
sr.nextBytes(k);
SecretKeySpec ks = new SecretKeySpec(k, "AES");
Cipher enc = Cipher.getInstance("AES/OFB/NoPadding", "BC");
sr.nextBytes(iv);
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv));
C[0] = enc.doFinal(M[0]);
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv));
C[1] = enc.doFinal(M[1]);
} catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | InvalidKeyException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException ex) {
}
}
}
| 1,078 | 28.972222 | 108 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/nullcipher/src/main/java/cib/nullcipher/UseNullCipher1.java | package cib.nullcipher;
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.NullCipher;
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 UseNullCipher1 {
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];
(new SecureRandom()).nextBytes(iv);
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(128);
Key k = g.generateKey();
Cipher enc = new NullCipher();
Cipher dec = new javax.crypto.NullCipher();
byte[] ct;
enc.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
ct = enc.doFinal(pt1);
dec.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
byte[] pt2 = dec.doFinal(ct);
}
}
| 1,448 | 31.2 | 101 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/nullcipher/src/main/java/cib/nullcipher/UseNullCipher2.java | package cib.nullcipher;
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.NullCipher;
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 UseNullCipher2 {
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];
(new SecureRandom()).nextBytes(iv);
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 = new NullCipher();
Cipher dec = new javax.crypto.NullCipher();
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,756 | 32.788462 | 101 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/paramsPBE/src/main/java/cib/paramsPBE/PBEwConstSalt1.java | package cib.paramsPBE;
import javax.crypto.*;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.spec.PBEKeySpec;
import org.bouncycastle.jce.provider.*;
//
public final class PBEwConstSalt1 {
@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;
salt = "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF".getBytes();
int iterationCount = 2048;
PBEKeySpec pbeks = new PBEKeySpec(password, salt, iterationCount);
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBEWithSHA256And128BitAES-CBC-BC", "BC");
Key sk = skf.generateSecret(pbeks);
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
c.init(Cipher.ENCRYPT_MODE, sk);
byte[] text = "Testando o AES..".getBytes();
byte[] enrypted = c.doFinal(text);
c.init(Cipher.DECRYPT_MODE, sk);
byte[] decrypted = c.doFinal(enrypted);
}
}
}
| 1,260 | 29.756098 | 117 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/paramsPBE/src/main/java/cib/paramsPBE/PBEwSmallCount1.java | package cib.paramsPBE;
import javax.crypto.*;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.spec.PBEKeySpec;
import org.bouncycastle.jce.provider.*;
//
public final class PBEwSmallCount1 {
@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];
(SecureRandom.getInstanceStrong()).nextBytes(salt);
int iterationCount = 20;
PBEKeySpec pbeks = new PBEKeySpec(password, salt, iterationCount);
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBEWithSHA256And128BitAES-CBC-BC", "BC");
Key sk = skf.generateSecret(pbeks);
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
c.init(Cipher.ENCRYPT_MODE, sk);
byte[] text = "Testando o AES..".getBytes();
byte[] enrypted = c.doFinal(text);
c.init(Cipher.DECRYPT_MODE, sk);
byte[] decrypted = c.doFinal(enrypted);
}
}
}
| 1,256 | 29.658537 | 117 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/paramsPBE/src/main/java/cib/paramsPBE/PBEwSmallSalt.java | package cib.paramsPBE;
import javax.crypto.*;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.spec.PBEKeySpec;
import org.bouncycastle.jce.provider.*;
public final class PBEwSmallSalt {
@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[2];
SecureRandom.getInstanceStrong().nextBytes(salt);
int iterationCount = 2048;
PBEKeySpec pbeks = new PBEKeySpec(password, salt, iterationCount);
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBEWithSHA256And128BitAES-CBC-BC", "BC");
Key sk = skf.generateSecret(pbeks);
Cipher c = Cipher.getInstance("AES/CTR/NoPadding", "BC");
c.init(Cipher.ENCRYPT_MODE, sk);
byte[] text = "Testando o AES..".getBytes();
byte[] encrypted = c.doFinal(text);
c.init(Cipher.DECRYPT_MODE, sk);
byte[] decrypted = c.doFinal(encrypted);
}
}
}
| 1,250 | 31.076923 | 117 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/predictableSeed/src/main/java/br/predictableSeed/LowEntropySeed1.java | package br.predictableSeed;
import java.util.Random;
import java.security.SecureRandom;
public final class LowEntropySeed1 {
public static void main(String[] args) {
try {
SecureRandom r3 = SecureRandom.getInstanceStrong();
r3.setSeed((new Random()).nextInt());
SecureRandom r4 = SecureRandom.getInstanceStrong();
r4.setSeed((new Random()).nextInt());
} catch (Exception e) {
}
}
}
| 408 | 18.47619 | 54 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/predictableSeed/src/main/java/br/predictableSeed/LowEntropySeed2.java | package br.predictableSeed;
import java.security.SecureRandom;
public final class LowEntropySeed2 {
public static void main(String[] args) {
try {
SecureRandom r3 = SecureRandom.getInstanceStrong();
r3.setSeed((int) (Math.random() * 10000));
SecureRandom r4 = SecureRandom.getInstanceStrong();
r4.setSeed((int) (100000 * Math.random()));
} catch (Exception e) {
}
}
}
| 393 | 19.736842 | 54 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/predictableSeed/src/main/java/br/predictableSeed/LowEntropySeed3.java | package br.predictableSeed;
import java.security.SecureRandom;
public final class LowEntropySeed3 {
public static void main(String[] args) {
try {
SecureRandom r3 = SecureRandom.getInstanceStrong();
r3.setSeed(System.currentTimeMillis());
SecureRandom r4 = SecureRandom.getInstanceStrong();
r4.setSeed(System.nanoTime());
} catch (Exception e) {
}
}
}
| 378 | 17.95 | 54 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/predictableSeed/src/main/java/br/predictableSeed/LowEntropySeed4.java | package br.predictableSeed;
import java.security.SecureRandom;
public final class LowEntropySeed4 {
public static void main(String[] args) {
try {
SecureRandom r3 = new SecureRandom();
r3.setSeed(System.nanoTime());
SecureRandom r4 = new SecureRandom();
r4.setSeed(System.nanoTime());
} catch (Exception e) {
}
}
}
| 341 | 16.1 | 41 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/predictableSeed/src/main/java/br/predictableSeed/ReusedSeed.java | package br.predictableSeed;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
public final class ReusedSeed {
public static void main(String[] args) {
try {
SecureRandom sr4 = SecureRandom.getInstance("SHA1PRNG", "SUN");
SecureRandom sr5 = SecureRandom.getInstance("SHA1PRNG", "SUN");
byte[] seed = sr4.generateSeed(32);
sr4.setSeed(seed);
sr5.setSeed(seed);
SecureRandom sr9 = SecureRandom.getInstance("Windows-PRNG", "SunMSCAPI");
SecureRandom sr0 = SecureRandom.getInstance("Windows-PRNG", "SunMSCAPI");
sr9.setSeed(seed);
sr0.setSeed(seed);
} catch (NoSuchAlgorithmException | NoSuchProviderException e) {
}
}
}
| 735 | 26.259259 | 76 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/printPrivSecKey/src/main/java/cib/printPrivSecKey/PrintDHPrivKey1.java | package cib.printPrivSecKey;
import java.security.*;
import java.security.spec.*;
import java.util.Arrays;
import javax.crypto.*;
public final class PrintDHPrivKey1 {
public static void main(String argv[]) {
try {
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("DH", "SunJCE");
kpg1.initialize(2048);
KeyPair kp1 = kpg1.generateKeyPair();
KeyAgreement ka1 = KeyAgreement.getInstance("DH", "SunJCE");
ka1.init(kp1.getPrivate());
byte[] pubKey1 = kp1.getPublic().getEncoded();
KeyFactory kf1 = KeyFactory.getInstance("DH", "SunJCE");
X509EncodedKeySpec x509ks = new X509EncodedKeySpec(pubKey1);
PublicKey apk1 = kf1.generatePublic(x509ks);
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance("DH", "SunJCE");
kpg2.initialize(2048);
KeyPair kp2 = kpg2.generateKeyPair();
KeyAgreement ka2 = KeyAgreement.getInstance("DH", "SunJCE");
ka2.init(kp2.getPrivate());
byte[] pubKey2 = kp2.getPublic().getEncoded();
KeyFactory kf2 = KeyFactory.getInstance("DH", "SunJCE");
x509ks = new X509EncodedKeySpec(pubKey2);
PublicKey apk2 = kf2.generatePublic(x509ks);
ka1.doPhase(apk2, true);
byte[] genSec1 = ka1.generateSecret();
ka2.doPhase(apk1, true);
byte[] genSec2 = ka2.generateSecret();
if (!Arrays.equals(genSec1, genSec2)) {
throw new Exception("Shared secrets differ");
}
} catch (Exception e) {
}
}
}
| 1,392 | 29.955556 | 72 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/printPrivSecKey/src/main/java/cib/printPrivSecKey/PrintDHSecret1.java | package cib.printPrivSecKey;
import java.security.*;
import java.security.spec.*;
import java.util.Arrays;
import javax.crypto.*;
public final class PrintDHSecret1 {
public static void main(String argv[]) {
try {
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("DH", "SunJCE");
kpg1.initialize(2048);
KeyPair kp1 = kpg1.generateKeyPair();
KeyAgreement ka1 = KeyAgreement.getInstance("DH", "SunJCE");
ka1.init(kp1.getPrivate());
byte[] pubKey1 = kp1.getPublic().getEncoded();
KeyFactory kf1 = KeyFactory.getInstance("DH", "SunJCE");
X509EncodedKeySpec x509ks = new X509EncodedKeySpec(pubKey1);
PublicKey apk1 = kf1.generatePublic(x509ks);
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance("DH", "SunJCE");
kpg2.initialize(2048);
KeyPair kp2 = kpg2.generateKeyPair();
KeyAgreement ka2 = KeyAgreement.getInstance("DH", "SunJCE");
ka2.init(kp2.getPrivate());
byte[] pubKey2 = kp2.getPublic().getEncoded();
KeyFactory kf2 = KeyFactory.getInstance("DH", "SunJCE");
x509ks = new X509EncodedKeySpec(pubKey2);
PublicKey apk2 = kf2.generatePublic(x509ks);
ka1.doPhase(apk2, true);
byte[] genSec1 = ka1.generateSecret();
ka2.doPhase(apk1, true);
byte[] genSec2 = ka2.generateSecret();
if (!Arrays.equals(genSec1, genSec2)) {
throw new Exception("Shared secrets differ");
}
} catch (Exception e) {
}
}
}
| 1,391 | 29.933333 | 72 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/printPrivSecKey/src/main/java/cib/printPrivSecKey/PrintECDHPrivKey1.java | package cib.printPrivSecKey;
import java.security.*;
import java.security.spec.*;
import java.util.Arrays;
import javax.crypto.*;
public final class PrintECDHPrivKey1 {
public static void main(String argv[]) {
try {
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("EC", "SunEC");
kpg1.initialize(521);
KeyPair kp1 = kpg1.generateKeyPair();
KeyAgreement ka1 = KeyAgreement.getInstance("ECDH", "SunEC");
ka1.init(kp1.getPrivate());
byte[] pubKey1 = kp1.getPublic().getEncoded();
KeyFactory kf1 = KeyFactory.getInstance("EC", "SunEC");
X509EncodedKeySpec x509ks = new X509EncodedKeySpec(pubKey1);
PublicKey apk1 = kf1.generatePublic(x509ks);
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance("EC", "SunEC");
kpg2.initialize(521);
KeyPair kp2 = kpg2.generateKeyPair();
KeyAgreement ka2 = KeyAgreement.getInstance("ECDH", "SunEC");
ka2.init(kp2.getPrivate());
byte[] pubKey2 = kp2.getPublic().getEncoded();
KeyFactory kf2 = KeyFactory.getInstance("EC", "SunEC");
x509ks = new X509EncodedKeySpec(pubKey2);
PublicKey apk2 = kf2.generatePublic(x509ks);
ka1.doPhase(apk2, true);
byte[] genSec1 = ka1.generateSecret();
ka2.doPhase(apk1, true);
byte[] genSec2 = ka2.generateSecret();
if (!Arrays.equals(genSec1, genSec2)) {
throw new Exception("Shared secrets differ");
}
} catch (Exception e) {
}
}
}
| 1,390 | 29.911111 | 71 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/printPrivSecKey/src/main/java/cib/printPrivSecKey/PrintECDHSecret1.java | package cib.printPrivSecKey;
import java.security.*;
import java.security.spec.*;
import java.util.Arrays;
import javax.crypto.*;
public final class PrintECDHSecret1 {
public static void main(String argv[]) {
try {
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("EC", "SunEC");
kpg1.initialize(521);
KeyPair kp1 = kpg1.generateKeyPair();
KeyAgreement ka1 = KeyAgreement.getInstance("ECDH", "SunEC");
ka1.init(kp1.getPrivate());
byte[] pubKey1 = kp1.getPublic().getEncoded();
KeyFactory kf1 = KeyFactory.getInstance("EC", "SunEC");
X509EncodedKeySpec x509ks = new X509EncodedKeySpec(pubKey1);
PublicKey apk1 = kf1.generatePublic(x509ks);
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance("EC", "SunEC");
kpg2.initialize(521);
KeyPair kp2 = kpg2.generateKeyPair();
KeyAgreement ka2 = KeyAgreement.getInstance("ECDH", "SunEC");
ka2.init(kp2.getPrivate());
byte[] pubKey2 = kp2.getPublic().getEncoded();
KeyFactory kf2 = KeyFactory.getInstance("EC", "SunEC");
x509ks = new X509EncodedKeySpec(pubKey2);
PublicKey apk2 = kf2.generatePublic(x509ks);
ka1.doPhase(apk2, true);
byte[] genSec1 = ka1.generateSecret();
ka2.doPhase(apk1, true);
byte[] genSec2 = ka2.generateSecret();
if (!Arrays.equals(genSec1, genSec2)) {
throw new Exception("Shared secrets differ");
}
} catch (Exception e) {
}
}
}
| 1,389 | 29.888889 | 71 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/printPrivSecKey/src/main/java/cib/printPrivSecKey/PrintECDSAPrivKey1.java | package cib.printPrivSecKey;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Signature;
public final class PrintECDSAPrivKey1 {
public static void main(String[] args) throws Exception {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(571, new SecureRandom());
Signature sign = Signature.getInstance("SHA512WithECDSA", "SunEC");
KeyPair kp = kpg.generateKeyPair();
sign.initSign(kp.getPrivate(), new SecureRandom());
byte[] doc = "demo text".getBytes();
sign.update(doc);
byte[] signed = sign.sign();
Signature verifier = Signature.getInstance("SHA512WithECDSA", "SunEC");
verifier.initVerify(kp.getPublic());
verifier.update(doc);
boolean ok = verifier.verify(signed);
}
}
| 820 | 25.483871 | 73 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/printPrivSecKey/src/main/java/cib/printPrivSecKey/PrintPrivKey1.java | package cib.printPrivSecKey;
import javax.crypto.*;
import java.security.*;
import org.bouncycastle.jce.provider.*;
public final class PrintPrivKey1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 2048;
int hsize = 256;
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/OAEPwithSHA256andMGF1Padding", "BC");
Key pubk = kp.getPublic();
c.init(Cipher.ENCRYPT_MODE, pubk);
byte[] pt1 = "this is a text demo".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,021 | 27.388889 | 101 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/printPrivSecKey/src/main/java/cib/printPrivSecKey/PrintSecKey1.java | package cib.printPrivSecKey;
import java.io.UnsupportedEncodingException;
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 PrintSecKey1 {
public static void main(String args[]) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException,
UnsupportedEncodingException {
Security.addProvider(new BouncyCastleProvider());
byte[] pt1 = ("Testing String..").getBytes("UTF-8");
byte[] iv = new byte[16];
SecureRandom.getInstanceStrong().nextBytes(iv);
KeyGenerator g = KeyGenerator.getInstance("AES", "BC");
g.init(128);
Key k = g.generateKey();
String aes = "AES/CTR/NoPadding";
Cipher enc = Cipher.getInstance(aes, "BC");
Cipher dec = Cipher.getInstance(aes, "BC");
byte[] ct;
enc.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
ct = enc.doFinal(pt1);
dec.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
byte[] pt2 = dec.doFinal(ct);
dec.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
pt2 = dec.doFinal(ct);
}
}
| 1,657 | 32.16 | 117 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/riskyInsecureCrypto/src/main/java/wc/riskyInsecureCrypto/InsecureCrypto3DES.java | package wc.riskyInsecureCrypto;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.SecureRandom;
public final class InsecureCrypto3DES {
public static void main(String[] a) {
try {
byte[] msg = "msg demo".getBytes();
byte[] iv = new byte[8];
(new SecureRandom()).nextBytes(iv);
KeyGenerator kg = KeyGenerator.getInstance("DESede", "SunJCE");
kg.init(168);
Key k = kg.generateKey();
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);
iv = c.getIV();
c.init(Cipher.DECRYPT_MODE, k, aps);
byte[] pt = c.doFinal(ct);
} catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | InvalidKeyException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException e) {
System.out.println(e);
}
}
}
| 1,201 | 30.631579 | 108 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/riskyInsecureCrypto/src/main/java/wc/riskyInsecureCrypto/InsecureCryptoBlowfish.java | package wc.riskyInsecureCrypto;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
import java.security.spec.AlgorithmParameterSpec;
public final class InsecureCryptoBlowfish {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
byte[] msg = "This is a test Blowfsh".getBytes();
KeyGenerator kg = KeyGenerator.getInstance("Blowfish", "SunJCE");
kg.init(128);
byte[] iv = new byte[8];
(new SecureRandom()).nextBytes(iv);
Key k = kg.generateKey();
Cipher c = Cipher.getInstance("Blowfish/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);
}
}
| 937 | 30.266667 | 101 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/riskyInsecureCrypto/src/main/java/wc/riskyInsecureCrypto/InsecureCryptoDES.java | package wc.riskyInsecureCrypto;
import javax.crypto.*;
import javax.crypto.spec.*;
import java.security.*;
import java.security.spec.AlgorithmParameterSpec;
public final class InsecureCryptoDES {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
byte[] msg = "msg demo".getBytes();
KeyGenerator kg = KeyGenerator.getInstance("DES", "SunJCE");
kg.init(56);
byte[] iv = new byte[8];
(new SecureRandom()).nextBytes(iv);
Key k = kg.generateKey();
Cipher c = Cipher.getInstance("DES/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);
byte[] pt = c.doFinal(ct);
}
}
| 899 | 32.333333 | 101 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/riskyInsecureCrypto/src/main/java/wc/riskyInsecureCrypto/InsecureCryptoDES_StreamCipher.java | package wc.riskyInsecureCrypto;
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.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
public final class InsecureCryptoDES_StreamCipher {
public static void main(String[] a) {
try {
KeyGenerator kg = KeyGenerator.getInstance("DES", "SunJCE");
kg.init(56);
byte[] iv = new byte[8];
(new SecureRandom()).nextBytes(iv);
Key k = kg.generateKey();
byte[] msg = "msg demo".getBytes();
Cipher cf = Cipher.getInstance("DES/CFB8/NoPadding", "SunJCE");
AlgorithmParameterSpec aps = new IvParameterSpec(iv);
cf.init(Cipher.ENCRYPT_MODE, k, aps);
byte[] ct = cf.doFinal(msg);
cf.init(Cipher.DECRYPT_MODE, k, aps);
byte[] pt = cf.doFinal(ct);
iv = new byte[8];
(new SecureRandom()).nextBytes(iv);
k = kg.generateKey();
msg = "msg demo 2".getBytes();
cf = Cipher.getInstance("DES/CFB64/NoPadding", "SunJCE");
aps = new IvParameterSpec(iv);
cf.init(Cipher.ENCRYPT_MODE, k, aps);
ct = cf.doFinal(msg);
cf.init(Cipher.DECRYPT_MODE, k, aps);
pt = cf.doFinal(ct);
iv = new byte[8];
(new SecureRandom()).nextBytes(iv);
k = kg.generateKey();
msg = "msg demo 3".getBytes();
cf = Cipher.getInstance("DES/OFB8/NoPadding", "SunJCE");
aps = new IvParameterSpec(iv);
cf.init(Cipher.ENCRYPT_MODE, k, aps);
ct = cf.doFinal(msg);
cf.init(Cipher.DECRYPT_MODE, k, aps);
pt = cf.doFinal(ct);
iv = new byte[8];
(new SecureRandom()).nextBytes(iv);
k = kg.generateKey();
msg = "msg 4".getBytes();
cf = Cipher.getInstance("DES/OFB64/NoPadding", "SunJCE");
aps = new IvParameterSpec(iv);
cf.init(Cipher.ENCRYPT_MODE, k, aps);
ct = cf.doFinal(msg);
cf.init(Cipher.DECRYPT_MODE, k, aps);
pt = cf.doFinal(ct);
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException
| InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException
| NoSuchProviderException e) {
}
}
}
| 2,209 | 28.078947 | 90 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/riskyInsecureCrypto/src/main/java/wc/riskyInsecureCrypto/InsecureCryptoPBE.java | package wc.riskyInsecureCrypto;
import javax.crypto.*;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.spec.PBEKeySpec;
import org.bouncycastle.jce.provider.*;
public final class InsecureCryptoPBE {
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("PBEWithMD5andDES", "SunJCE");
Key sk = skf.generateSecret(pbeks);
skf = SecretKeyFactory.getInstance("PBEWithSHA1andDES", "BC");
sk = skf.generateSecret(pbeks);
}
}
}
| 1,039 | 29.588235 | 117 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/riskyInsecureCrypto/src/main/java/wc/riskyInsecureCrypto/InsecureCryptoRC4_StreamCipher.java | package wc.riskyInsecureCrypto;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import javax.crypto.*;
public final class InsecureCryptoRC4_StreamCipher {
public static void main(String[] a) {
try {
Cipher cf = Cipher.getInstance("ARCFOUR/ECB/NoPadding", "SunJCE");
KeyGenerator kg = KeyGenerator.getInstance("ARCFOUR", "SunJCE");
kg.init(128);
Key k = kg.generateKey();
byte[] msg = "demo msg".getBytes();
cf.init(Cipher.ENCRYPT_MODE, k);
byte[] ct = cf.doFinal(msg);
cf.init(Cipher.DECRYPT_MODE, k);
byte[] pt = cf.doFinal(ct);
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException
| BadPaddingException | NoSuchProviderException e) {
}
}
}
| 855 | 28.517241 | 110 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/sideChannelAttacks/src/main/java/pdf/sideChannelAttacks/HashVerificationVariableTime.java |
package pdf.sideChannelAttacks;
import javax.crypto.*;
import java.security.*;
import org.bouncycastle.jce.provider.*;
import org.bouncycastle.util.Arrays;
public final class HashVerificationVariableTime {
public static void main(String args[]) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException, NoSuchProviderException {
Security.addProvider(new BouncyCastleProvider());
MessageDigest md = MessageDigest.getInstance("SHA512", "BC");
boolean ok;
long t1, t2;
long t[] = new long[64], tt[] = new long[64], ttt[] = new long[64];
long tttt[] = new long[64], ttttt[] = new long[64];
md.reset();
byte[] hash1 = md.digest("demo text".getBytes());
for (int j = 0; j < 1; j++) {
for (int i = 0; i < t.length; i++) {
md.reset();
byte[] hash2 = md.digest("demo text".getBytes());
hash2[i] = (byte) (hash2[i] ^ 0x01);
t1 = System.nanoTime();
ok = isEqualToVar(hash2, hash1);
t2 = System.nanoTime();
t[i] = t2 - t1;
}
for (int i = 0; i < t.length; i++) {
md.reset();
byte[] hash2 = md.digest("demo text".getBytes());
hash2[i] = (byte) (hash2[i] ^ 0x01);
t1 = System.nanoTime();
ok = MessageDigest.isEqual(hash2, hash1);
t2 = System.nanoTime();
tt[i] = t2 - t1;
}
for (int i = 0; i < t.length; i++) {
md.reset();
byte[] hash2 = md.digest("demo text".getBytes());
hash2[i] = (byte) (hash2[i] ^ 0x01);
t1 = System.nanoTime();
ok = isEqualToConst(hash2, hash1);
t2 = System.nanoTime();
ttt[i] = t2 - t1;
}
for (int i = 0; i < t.length; i++) {
md.reset();
byte[] hash2 = md.digest("demo text".getBytes());
hash2[i] = (byte) (hash2[i] ^ 0x01);
t1 = System.nanoTime();
ok = Arrays.areEqual(hash2, hash1);
t2 = System.nanoTime();
tttt[i] = t2 - t1;
}
for (int i = 0; i < t.length; i++) {
md.reset();
byte[] hash2 = md.digest("demo text".getBytes());
hash2[i] = (byte) (hash2[i] ^ 0x01);
t1 = System.nanoTime();
ok = Arrays.constantTimeAreEqual(hash2, hash1);
t2 = System.nanoTime();
ttttt[i] = t2 - t1;
}
}
md.reset();
byte[] hash2 = md.digest("demo text".getBytes());
t1 = System.nanoTime();
ok = isEqualToConst(hash2, hash1);
t2 = System.nanoTime();
}
static boolean isEqualToVar(byte[] a, byte[] b) {
boolean igual = true;
if (a.length != b.length) {
igual = false;
} else {
for (int i = 0; i < a.length; i++) {
if (a[i] != b[i]) {
igual = false;
break;
}
}
}
return igual;
}
static boolean isEqualToConst(byte[] a, byte[] b) {
boolean igual = true;
if (a.length != b.length) {
igual = false;
} else {
for (int i = 0; i < a.length; i++) {
if (a[i] != b[i]) {
igual = false;
}
}
}
return igual;
}
}
| 2,847 | 24.657658 | 117 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/sideChannelAttacks/src/main/java/pdf/sideChannelAttacks/MacVerificationVariableTime.java | package pdf.sideChannelAttacks;
import java.security.*;
import java.util.Arrays;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
public final class MacVerificationVariableTime {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
KeyGenerator g = KeyGenerator.getInstance("HMACSHA256", "SunJCE");
g.init(256);
Key k1 = g.generateKey();
Mac m = Mac.getInstance("HMACSHA256", "SunJCE");
byte[] msg = "This is a test for MAC".getBytes();
m.init(k1);
byte[] tag = m.doFinal(msg);
SecretKeySpec sks = new SecretKeySpec(k1.getEncoded(), "HMACSHA256");
m.init(sks);
byte[] tag2 = m.doFinal(msg);
boolean ok = Arrays.equals(tag2, tag);
}
}
| 859 | 27.666667 | 101 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/sideChannelAttacks/src/main/java/pdf/sideChannelAttacks/PaddingOracle.java | package pdf.sideChannelAttacks;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class PaddingOracle {
private static final byte[] text = ("demo text").getBytes();
private static final byte[] k = "00112233445566778899AABBCCDDEEFF".getBytes();
public static final byte[] iv = "0123456789ABCDEF0123456789ABCDEF".getBytes();
private static final SecretKeySpec ks = new SecretKeySpec(k, "AES");
static {
Security.addProvider(new BouncyCastleProvider());
}
public static boolean oracle(byte[] iv, byte[] c) {
boolean ok = true;
try {
Cipher enc = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
enc.init(Cipher.DECRYPT_MODE, ks, new IvParameterSpec(iv));
enc.doFinal(c);
} catch (BadPaddingException e) {
ok = false;
} catch (NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | InvalidKeyException
| InvalidAlgorithmParameterException | IllegalBlockSizeException ex) {
}
return ok;
}
public static byte[] encripta() {
byte[] encrypted = null;
try {
Cipher enc = Cipher.getInstance("AES/CBC/PKCS7Padding", "BC");
enc.init(Cipher.ENCRYPT_MODE, ks, new IvParameterSpec(iv));
encrypted = enc.doFinal(text);
} catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException | NoSuchProviderException
| NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException ex) {
}
return encrypted;
}
}
| 1,518 | 32.021739 | 108 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/staticCounterCTR/src/main/java/ivm/staticCounterCTR/StaticCounterCTR1.java | package ivm.staticCounterCTR;
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 StaticCounterCTR1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
byte[] pt1 = ("static counter").getBytes();
byte[] ictr = 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();
Cipher enc = Cipher.getInstance("AES/CTR/NoPadding", "BC");
Cipher dec = Cipher.getInstance("AES/CTR/NoPadding", "BC");
byte[] ct;
enc.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(ictr));
ct = enc.doFinal(pt1);
byte[] ctr = enc.getIV();
dec.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(ctr));
byte[] pt2 = dec.doFinal(ct);
enc.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(ictr));
ct = enc.doFinal(pt1);
ctr = enc.getIV();
dec.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(ctr));
pt2 = dec.doFinal(ct);
}
}
| 1,850 | 34.596154 | 107 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/statisticPRNG/src/main/java/br/statisticPRNG/UsingRandom1.java | package br.statisticPRNG;
import java.util.Random;
public final class UsingRandom1 {
public static void main(String[] args) {
try {
Random r1 = new Random();
Random r2 = new Random();
} catch (Exception e) {
}
}
}
| 233 | 12.764706 | 41 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/statisticPRNG/src/main/java/br/statisticPRNG/UsingRandom2.java | package br.statisticPRNG;
import java.util.Random;
import java.security.SecureRandom;
public final class UsingRandom2 {
public static void main(String[] args) {
try {
Random r3 = new Random();
r3.setSeed((SecureRandom.getInstanceStrong()).nextInt());
Random r4 = new Random();
r4.setSeed((SecureRandom.getInstanceStrong()).nextInt());
} catch (Exception e) {
}
}
}
| 391 | 17.666667 | 60 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/undefinedCSP/src/main/java/cai/undefinedCSP/UndefinedProvider1.java | package cai.undefinedCSP;
import java.security.KeyPairGenerator;
import java.security.Signature;
public final class UndefinedProvider1 {
public static void main(String[] args) throws Exception {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("DSA");
Signature signer = Signature.getInstance("SHA256WithDSA");
Signature verifier = Signature.getInstance("SHA256WithDSA");
}
}
| 392 | 23.5625 | 62 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/undefinedCSP/src/main/java/cai/undefinedCSP/UndefinedProvider2.java | package cai.undefinedCSP;
import java.security.KeyPairGenerator;
import java.security.Signature;
public final class UndefinedProvider2 {
public static void main(String[] args) throws Exception {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");
Signature signer = Signature.getInstance("SHA512WithECDSA");
Signature verifier = Signature.getInstance("SHA512WithECDSA");
}
}
| 395 | 23.75 | 64 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/undefinedCSP/src/main/java/cai/undefinedCSP/UndefinedProvider3.java | package cai.undefinedCSP;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
public final class UndefinedProvider3 {
public static void main(String[] args) {
try {
SecureRandom r1 = SecureRandom.getInstance("SHA1PRNG");
SecureRandom r2 = SecureRandom.getInstanceStrong();
r1.setSeed(r2.nextLong());
} catch (NoSuchAlgorithmException e) {
}
}
}
| 397 | 19.947368 | 58 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/undefinedCSP/src/main/java/cai/undefinedCSP/UndefinedProvider4.java | package cai.undefinedCSP;
import java.security.*;
import javax.crypto.*;
public final class UndefinedProvider4 {
public static void main(String argv[]) {
try {
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance("DH");
KeyAgreement ka1 = KeyAgreement.getInstance("DH");
KeyFactory kf1 = KeyFactory.getInstance("DH");
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance("DH");
KeyAgreement ka2 = KeyAgreement.getInstance("DH");
KeyFactory kf2 = KeyFactory.getInstance("DH");
} catch (Exception e) {
}
}
}
| 536 | 24.571429 | 62 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/undefinedCSP/src/main/java/cai/undefinedCSP/UndefinedProvider5.java | package cai.undefinedCSP;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
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 UndefinedProvider5 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
KeyGenerator g = KeyGenerator.getInstance("AES");
Cipher enc = Cipher.getInstance("AES/CTR/NoPadding");
Cipher dec = Cipher.getInstance("AES/CTR/NoPadding");
}
}
| 951 | 33 | 101 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/undefinedCSP/src/main/java/cai/undefinedCSP/UndefinedProvider6.java | package cai.undefinedCSP;
import javax.crypto.*;
import java.security.*;
public final class UndefinedProvider6 {
public static void main(String args[]) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
BadPaddingException, IllegalBlockSizeException, NoSuchProviderException {
byte[] msg = "demo msg".getBytes();
KeyGenerator kg = KeyGenerator.getInstance("AES");
kg.init(256);
Key key = kg.generateKey();
Cipher ciph = Cipher.getInstance("AES");
ciph.init(Cipher.ENCRYPT_MODE, key);
byte[] encrypted = ciph.doFinal(msg);
ciph.init(Cipher.DECRYPT_MODE, key);
byte[] decrypted = ciph.doFinal(encrypted);
}
}
| 660 | 30.47619 | 117 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/undefinedCSP/src/main/java/cai/undefinedCSP/UndefinedProvider7.java | package cai.undefinedCSP;
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 UndefinedProvider7 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 512;
int hsize = 160;
int maxLenBytes = (ksize - 2 * hsize) / 8 - 2;
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
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("RSA");
c.init(Cipher.ENCRYPT_MODE, kp.getPublic(), OAEPps);
byte[] pt = "demo text".substring(0, maxLenBytes).getBytes();
byte[] ct = c.doFinal(pt);
c.init(Cipher.DECRYPT_MODE, kp.getPrivate(), OAEPps);
byte[] pt2 = c.doFinal(ct);
}
}
| 1,189 | 28.75 | 103 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/undefinedCSP/src/main/java/cai/undefinedCSP/UndefinedProvider8.java | package cai.undefinedCSP;
import java.security.InvalidKeyException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
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 UndefinedProvider8 {
public static void main(String args[]) {
try {
Security.addProvider(new BouncyCastleProvider());
byte[] msg1 = ("Insecure default RSA.").getBytes();
KeyPairGenerator g = KeyPairGenerator.getInstance("RSA");
g.initialize(2048);
KeyPair kp = g.generateKeyPair();
Cipher enc = Cipher.getInstance("RSA");
enc.init(Cipher.ENCRYPT_MODE, kp.getPublic());
Cipher dec = Cipher.getInstance("RSA");
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[] pt = dec.doFinal(ct[i]);
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException
| BadPaddingException e) {
}
}
}
| 1,234 | 29.875 | 110 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakConfigsRSA/src/main/java/pkc/enc/weakConfigsRSA/ImproperConfigRSA_1024x160_1.java |
package pkc.enc.weakConfigsRSA;
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 ImproperConfigRSA_1024x160_1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 1024;
int hsize = 160;
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("RSA/None/OAEPPadding", "BC");
c.init(Cipher.ENCRYPT_MODE, kp.getPublic(), OAEPps);
byte[] pt1 = "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,238 | 29.219512 | 103 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakConfigsRSA/src/main/java/pkc/enc/weakConfigsRSA/ImproperConfigRSA_1024x256_1.java |
package pkc.enc.weakConfigsRSA;
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 ImproperConfigRSA_1024x256_1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 1024;
int hsize = 256;
int maxLenBytes = (ksize - 2 * hsize) / 8 - 2;
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA", "BC");
kpg.initialize(ksize);
KeyPair kp = kpg.generateKeyPair();
MGF1ParameterSpec mgf1ps = MGF1ParameterSpec.SHA256;
OAEPParameterSpec OAEPps = new OAEPParameterSpec("SHA-256", "MGF1", mgf1ps, PSource.PSpecified.DEFAULT);
Cipher c = Cipher.getInstance("RSA/None/OAEPPadding", "BC");
c.init(Cipher.ENCRYPT_MODE, kp.getPublic(), OAEPps);
byte[] pt1 = "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,243 | 29.341463 | 106 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakConfigsRSA/src/main/java/pkc/enc/weakConfigsRSA/ImproperConfigRSA_1024x384_1.java |
package pkc.enc.weakConfigsRSA;
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 ImproperConfigRSA_1024x384_1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 1024;
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");
c.init(Cipher.ENCRYPT_MODE, kp.getPublic(), OAEPps);
byte[] pt1 = "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,243 | 29.341463 | 106 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakConfigsRSA/src/main/java/pkc/enc/weakConfigsRSA/ImproperConfigRSA_2048x160_1.java | package pkc.enc.weakConfigsRSA;
import javax.crypto.*;
import java.security.*;
import java.security.spec.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.*;
public final class ImproperConfigRSA_2048x160_1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 2048;
int hsize = 160;
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");
c.init(Cipher.ENCRYPT_MODE, kp.getPublic(), OAEPps);
byte[] pt1 = "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,209 | 29.25 | 106 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakConfigsRSA/src/main/java/pkc/enc/weakConfigsRSA/ImproperConfigRSA_3072x160_1.java | package pkc.enc.weakConfigsRSA;
import javax.crypto.*;
import java.security.*;
import java.security.spec.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.*;
public final class ImproperConfigRSA_3072x160_1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 3072;
int hsize = 160;
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");
c.init(Cipher.ENCRYPT_MODE, kp.getPublic(), OAEPps);
byte[] pt1 = "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,209 | 29.25 | 106 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakConfigsRSA/src/main/java/pkc/enc/weakConfigsRSA/ImproperConfigRSA_384x160_1.java | package pkc.enc.weakConfigsRSA;
import javax.crypto.*;
import java.security.*;
import java.security.spec.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.*;
public final class ImproperConfigRSA_384x160_1 {
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.SHA384;
OAEPParameterSpec OAEPps = new OAEPParameterSpec("SHA-384", "MGF1", mgf1ps, PSource.PSpecified.DEFAULT);
Cipher c = Cipher.getInstance(rsaName, "BC");
c.init(Cipher.ENCRYPT_MODE, kp.getPublic(), OAEPps);
byte[] pt1 = "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,235 | 29.146341 | 106 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakConfigsRSA/src/main/java/pkc/enc/weakConfigsRSA/ImproperConfigRSA_4096x160_1.java | package pkc.enc.weakConfigsRSA;
import javax.crypto.*;
import java.security.*;
import java.security.spec.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.*;
public final class ImproperConfigRSA_4096x160_1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 4096;
int hsize = 160;
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");
c.init(Cipher.ENCRYPT_MODE, kp.getPublic(), OAEPps);
byte[] pt1 = "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,209 | 29.25 | 106 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakConfigsRSA/src/main/java/pkc/enc/weakConfigsRSA/ImproperConfigRSA_512x160_1.java | package pkc.enc.weakConfigsRSA;
import javax.crypto.*;
import java.security.*;
import java.security.spec.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.*;
public final class ImproperConfigRSA_512x160_1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 512;
int hsize = 160;
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");
c.init(Cipher.ENCRYPT_MODE, kp.getPublic(), OAEPps);
byte[] pt1 = "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,207 | 29.2 | 106 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakConfigsRSA/src/main/java/pkc/enc/weakConfigsRSA/ImproperConfigRSA_768x160_1.java | package pkc.enc.weakConfigsRSA;
import javax.crypto.*;
import java.security.*;
import java.security.spec.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.*;
public final class ImproperConfigRSA_768x160_1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 768;
int hsize = 160;
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");
c.init(Cipher.ENCRYPT_MODE, kp.getPublic(), OAEPps);
byte[] pt1 = "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,207 | 29.2 | 106 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakConfigsRSA/src/main/java/pkc/enc/weakConfigsRSA/ImproperConfigRSA_768x256_1.java | package pkc.enc.weakConfigsRSA;
import javax.crypto.*;
import java.security.*;
import java.security.spec.*;
import javax.crypto.spec.*;
import org.bouncycastle.jce.provider.*;
public final class ImproperConfigRSA_768x256_1 {
public static void main(String args[])
throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, BadPaddingException,
IllegalBlockSizeException, NoSuchProviderException, InvalidAlgorithmParameterException {
Security.addProvider(new BouncyCastleProvider());
int ksize = 768;
int hsize = 256;
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");
c.init(Cipher.ENCRYPT_MODE, kp.getPublic(), OAEPps);
byte[] pt1 = "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,207 | 29.2 | 106 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakSignatureECDSA/src/main/java/pkc/sign/weakSignatureECDSA/RepeatedMessageNonceECDSA_1.java | package pkc.sign.weakSignatureECDSA;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Signature;
import org.bouncycastle.util.Arrays;
public final class RepeatedMessageNonceECDSA_1 {
public static void main(String[] args) throws Exception {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(256, SecureRandom.getInstanceStrong());
KeyPair kp = kpg.generateKeyPair();
SecureRandom sr1 = SecureRandom.getInstance("SHA1PRNG", "SUN");
byte[] seed = sr1.generateSeed(24);
sr1.setSeed(seed);
Signature signer1 = Signature.getInstance("SHA256withECDSA", "SunEC");
signer1.initSign(kp.getPrivate(), sr1);
byte[] doc = "demo doc".getBytes();
signer1.update(doc);
byte[] sign1 = signer1.sign();
SecureRandom sr2 = SecureRandom.getInstance("SHA1PRNG", "SUN");
sr2.setSeed(seed);
Signature signer2 = Signature.getInstance("SHA256withECDSA", "SunEC");
signer2.initSign(kp.getPrivate(), sr2);
doc = "demo doc".getBytes();
signer2.update(doc);
byte[] sign2 = signer2.sign();
boolean ok = Arrays.areEqual(sign1, sign2);
}
}
| 1,168 | 27.512195 | 72 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakSignatureECDSA/src/main/java/pkc/sign/weakSignatureECDSA/RepeatedMessageNonceECDSA_2.java | package pkc.sign.weakSignatureECDSA;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Signature;
import org.bouncycastle.util.Arrays;
public final class RepeatedMessageNonceECDSA_2 {
public static void main(String[] args) throws Exception {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(256, SecureRandom.getInstanceStrong());
KeyPair kp = kpg.generateKeyPair();
byte[] seed = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
SecureRandom sr1 = SecureRandom.getInstance("SHA1PRNG", "SUN");
sr1.setSeed(seed);
Signature signer1 = Signature.getInstance("SHA256withECDSA", "SunEC");
signer1.initSign(kp.getPrivate(), sr1);
byte[] doc = "demo doc".getBytes();
signer1.update(doc);
byte[] sign1 = signer1.sign();
SecureRandom sr2 = SecureRandom.getInstance("SHA1PRNG", "SUN");
sr2.setSeed(seed);
Signature signer2 = Signature.getInstance("SHA256withECDSA", "SunEC");
signer2.initSign(kp.getPrivate(), sr2);
doc = "demo doc".getBytes();
signer2.update(doc);
byte[] sign2 = signer2.sign();
boolean ok = Arrays.areEqual(sign1, sign2);
}
}
| 1,241 | 28.571429 | 109 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakSignatureECDSA/src/main/java/pkc/sign/weakSignatureECDSA/RepeatedMessageNonceECDSA_3.java | package pkc.sign.weakSignatureECDSA;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.spec.ECGenParameterSpec;
import org.bouncycastle.util.Arrays;
public final class RepeatedMessageNonceECDSA_3 {
public static void main(String[] args) throws Exception {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp256r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
byte[] seed = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
SecureRandom sr1 = SecureRandom.getInstance("SHA1PRNG", "SUN");
sr1.setSeed(seed);
Signature signer1 = Signature.getInstance("SHA256withECDSA", "SunEC");
signer1.initSign(kp.getPrivate(), sr1);
byte[] doc = "demo doc".getBytes();
signer1.update(doc);
byte[] sign1 = signer1.sign();
SecureRandom sr2 = SecureRandom.getInstance("SHA1PRNG", "SUN");
sr2.setSeed(seed);
Signature signer2 = Signature.getInstance("SHA256withECDSA", "SunEC");
signer2.initSign(kp.getPrivate(), sr2);
doc = "demo doc".getBytes();
signer2.update(doc);
byte[] sign2 = signer2.sign();
boolean ok = Arrays.areEqual(sign1, sign2);
}
}
| 1,320 | 28.355556 | 109 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakSignatureECDSA/src/main/java/pkc/sign/weakSignatureECDSA/RepeatedMessageNonceECDSA_4.java | package pkc.sign.weakSignatureECDSA;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.spec.ECGenParameterSpec;
import org.bouncycastle.util.Arrays;
public final class RepeatedMessageNonceECDSA_4 {
public static void main(String[] args) throws Exception {
ECGenParameterSpec ecps = new ECGenParameterSpec("secp256r1");
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(ecps);
KeyPair kp = kpg.generateKeyPair();
SecureRandom sr1 = new SecureRandom();
byte[] seed = sr1.generateSeed(24);
sr1.setSeed(seed);
Signature signer1 = Signature.getInstance("SHA256withECDSA", "SunEC");
signer1.initSign(kp.getPrivate(), sr1);
byte[] doc = "demo doc".getBytes();
signer1.update(doc);
byte[] sign1 = signer1.sign();
SecureRandom sr2 = new SecureRandom();
sr2.setSeed(seed);
Signature signer2 = Signature.getInstance("SHA256withECDSA", "SunEC");
signer2.initSign(kp.getPrivate(), sr2);
doc = "demo doc".getBytes();
signer2.update(doc);
byte[] sign2 = signer2.sign();
boolean ok = Arrays.areEqual(sign1, sign2);
}
}
| 1,197 | 26.227273 | 72 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakSignatureECDSA/src/main/java/pkc/sign/weakSignatureECDSA/SUN_80bits_ECDSA112wNONE1.java | package pkc.sign.weakSignatureECDSA;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.security.Signature;
public final class SUN_80bits_ECDSA112wNONE1 {
public static void main(String[] args) throws Exception {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(112, new SecureRandom());
Signature sign = Signature.getInstance("NONEwithECDSA", "SunEC");
KeyPair kp = kpg.generateKeyPair();
sign.initSign(kp.getPrivate(), new SecureRandom());
byte[] doc = "demo doc".getBytes();
MessageDigest md1 = MessageDigest.getInstance("SHA1", "SUN");
md1.update(doc);
byte[] hash = md1.digest();
sign.update(hash);
byte[] signed = sign.sign();
Signature verifier = Signature.getInstance("NONEwithECDSA", "SunEC");
MessageDigest md2 = MessageDigest.getInstance("SHA1", "SUN");
md2.update(doc);
byte[] hash2 = md2.digest();
verifier.initVerify(kp.getPublic());
verifier.update(hash2);
boolean ok = verifier.verify(signed);
}
}
| 1,096 | 27.868421 | 71 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakSignatureECDSA/src/main/java/pkc/sign/weakSignatureECDSA/SUN_80bits_ECDSA112wNONE2.java | package pkc.sign.weakSignatureECDSA;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.security.Signature;
public final class SUN_80bits_ECDSA112wNONE2 {
public static void main(String[] args) throws Exception {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(112, new SecureRandom());
Signature sign = Signature.getInstance("NONEwithECDSA", "SunEC");
KeyPair kp = kpg.generateKeyPair();
sign.initSign(kp.getPrivate(), new SecureRandom());
byte[] doc = "demo doc".getBytes();
MessageDigest md1 = MessageDigest.getInstance("SHA-256", "SUN");
md1.update(doc);
byte[] hash = md1.digest();
sign.update(hash);
byte[] signed = sign.sign();
Signature verifier = Signature.getInstance("NONEwithECDSA", "SunEC");
MessageDigest md2 = MessageDigest.getInstance("SHA-256", "SUN");
md2.update(doc);
byte[] hash2 = md2.digest();
verifier.initVerify(kp.getPublic());
verifier.update(hash2);
boolean ok = verifier.verify(signed);
}
}
| 1,102 | 28.026316 | 71 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakSignatureECDSA/src/main/java/pkc/sign/weakSignatureECDSA/SUN_80bits_ECDSA112wSHA1.java | package pkc.sign.weakSignatureECDSA;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Signature;
public final class SUN_80bits_ECDSA112wSHA1 {
public static void main(String[] args) throws Exception {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", "SunEC");
kpg.initialize(112, new SecureRandom());
Signature sign = Signature.getInstance("SHA1WithECDSA", "SunEC");
KeyPair kp = kpg.generateKeyPair();
sign.initSign(kp.getPrivate(), new SecureRandom());
byte[] doc = "demo doc".getBytes();
sign.update(doc);
byte[] signed = sign.sign();
Signature verifier = Signature.getInstance("SHA1WithECDSA", "SunEC");
verifier.initVerify(kp.getPublic());
verifier.update(doc);
boolean ok = verifier.verify(signed);
}
}
| 829 | 25.774194 | 71 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakSignatureRSA/src/main/java/pkc/sign/weakSignatureRSA/PKCS1Sign1024xSHA1_1.java | package pkc.sign.weakSignatureRSA;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.security.Signature;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class PKCS1Sign1024xSHA1_1 {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kg = KeyPairGenerator.getInstance("RSA", "BC");
kg.initialize(1024, new SecureRandom());
KeyPair kp = kg.generateKeyPair();
Signature sig = Signature.getInstance("SHA1withRSA", "BC");
byte[] m = "Testing RSA PKCS1".getBytes("UTF-8");
sig.initSign(kp.getPrivate(), new SecureRandom());
sig.update(m);
byte[] s = sig.sign();
sig.initVerify(kp.getPublic());
sig.update(m);
}
}
| 835 | 25.125 | 66 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakSignatureRSA/src/main/java/pkc/sign/weakSignatureRSA/PKCS1Sign1024xSHA256_2.java | package pkc.sign.weakSignatureRSA;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.security.Signature;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class PKCS1Sign1024xSHA256_2 {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kg = KeyPairGenerator.getInstance("RSA", "BC");
kg.initialize(1024, new SecureRandom());
KeyPair kp = kg.generateKeyPair();
Signature sig = Signature.getInstance("SHA256withRSA", "BC");
byte[] m = "Testing RSA PKCS1".getBytes("UTF-8");
sig.initSign(kp.getPrivate(), new SecureRandom());
sig.update(m);
byte[] s = sig.sign();
sig.initVerify(kp.getPublic());
sig.update(m);
}
}
| 839 | 25.25 | 66 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakSignatureRSA/src/main/java/pkc/sign/weakSignatureRSA/PSSw1024xSHA1_1.java | package pkc.sign.weakSignatureRSA;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.security.Signature;
import java.security.spec.PSSParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class PSSw1024xSHA1_1 {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kg = KeyPairGenerator.getInstance("RSA", "BC");
kg.initialize(1024, new SecureRandom());
KeyPair kp = kg.generateKeyPair();
Signature sig = Signature.getInstance("SHA1withRSAandMGF1", "BC");
sig.setParameter(PSSParameterSpec.DEFAULT);
byte[] m = "Testing RSA PSS w/ SHA1".getBytes("UTF-8");
sig.initSign(kp.getPrivate(), new SecureRandom());
sig.update(m);
byte[] s = sig.sign();
sig.initVerify(kp.getPublic());
sig.update(m);
}
}
| 933 | 26.470588 | 68 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/BragaCryptoBench/cryptomisuses/weakSignatureRSA/src/main/java/pkc/sign/weakSignatureRSA/PSSw1024xSHA256_2.java | package pkc.sign.weakSignatureRSA;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.SecureRandom;
import java.security.Security;
import java.security.Signature;
import java.security.spec.MGF1ParameterSpec;
import java.security.spec.PSSParameterSpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
public final class PSSw1024xSHA256_2 {
public static void main(String[] args) throws Exception {
Security.addProvider(new BouncyCastleProvider());
KeyPairGenerator kg = KeyPairGenerator.getInstance("RSA", "BC");
kg.initialize(2048, new SecureRandom());
KeyPair kp = kg.generateKeyPair();
Signature sig = Signature.getInstance("SHA256withRSAandMGF1", "BC");
PSSParameterSpec spec = new PSSParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256, 20, 1);
sig.setParameter(spec);
byte[] m = "Testing weak RSA-PSS".getBytes("UTF-8");
sig.initSign(kp.getPrivate(), new SecureRandom());
sig.update(m);
byte[] s = sig.sign();
sig.initVerify(kp.getPublic());
sig.update(m);
}
}
| 1,059 | 28.444444 | 99 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/Bugfixes/issue270/src/main/java/example/Launcher.java | package example;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
public class Launcher {
private KeyFactory keyFactory = KeyFactory.getInstance("ECJ");
public Launcher() throws NoSuchAlgorithmException {
}
public static void main(String [] args){
}
}
| 308 | 18.3125 | 66 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/CogniCryptDemoExample/src/main/java/example/ConstraintErrorExample.java | package example;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
/**
* This code contains a misuse example CogniCrypt_SAST of a Cipher object.
* CogniCrypt_SAST reports that the string argument to Cipher.getInstance("AES/ECB/PKCS5Padding") does not correspond the CrySL specification.
*
*/
public class ConstraintErrorExample {
public static void main(String...args) throws NoSuchAlgorithmException, NoSuchPaddingException {
Cipher instance = Cipher.getInstance("AES/ECB/PKCS5Padding");
}
}
| 575 | 31 | 143 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/CogniCryptDemoExample/src/main/java/example/IncompleOperationErrorExample.java | package example;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.SignatureException;
import javax.crypto.NoSuchPaddingException;
/**
* This code contains a misuse example CogniCrypt_SAST of a Signature object.
* CogniCrypt_SAST reports that the object is destroyed in an non-accepting state, or in other words the object is not used to fulfill a task.
*
*/
public class IncompleOperationErrorExample {
public static void main(String...args) throws NoSuchAlgorithmException, NoSuchPaddingException, GeneralSecurityException {
Signature instance = Signature.getInstance("SHA256withRSA");
instance.initSign(getPrivateKey());
instance.update(args[0].getBytes());
/**
* The following call is missing, therefore the Signature object is never actually used to compute a Signature.
*/
instance.sign();
IncompleOperationErrorExample ex = new IncompleOperationErrorExample();
ex.doInit();
ex.doUpate();
ex.doSign();
}
private Signature signature;
private void doInit() throws GeneralSecurityException {
signature = Signature.getInstance("SHA256withRSA");
signature.initSign(getPrivateKey());
}
private void doUpate() throws GeneralSecurityException {
signature.update("test".getBytes());
}
private void doSign() throws SignatureException {
/**
* The following call is missing, therefore the Signature object is never actually used to compute a Signature.
*/
// signature.sign();
}
private static PrivateKey getPrivateKey() throws GeneralSecurityException {
KeyPairGenerator kpgen = KeyPairGenerator.getInstance("RSA");
kpgen.initialize(2048);
KeyPair gp = kpgen.generateKeyPair();
return gp.getPrivate();
}
}
| 1,877 | 30.3 | 142 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/CogniCryptDemoExample/src/main/java/example/PredicateMissingExample.java | package example;
import java.security.GeneralSecurityException;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
/**
* This code contains a misuse example CogniCrypt_SAST of a Cipher object.
* CogniCrypt_SAST reports that the Cipher instance is initialized (call to init(...,key)) with a key that was not properly generated.
* The key generator is supplied with a key length of 46 (call to init(46)) which is not a correct key length for AES.
* Therefore, the generated secret key will be insecure and transitively the Cipher usage.
*
*/
public class PredicateMissingExample {
public static void main(String...args) throws GeneralSecurityException {
KeyGenerator keygen = KeyGenerator.getInstance("AES");
//CogniCryt_SAST reports an error in the next line saying that the key size is chosen inappropriately.
keygen.init(46);
SecretKey key = keygen.generateKey();
Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
//CogniCryt_SAST reports an error in the next line as the key flowing to this Cipher usage was not generated securely.
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encText = c.doFinal("".getBytes());
}
}
| 1,200 | 39.033333 | 134 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/CogniCryptDemoExample/src/main/java/example/TypestateErrorExample.java | package example;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.Signature;
/**
* This code contains a misuse example CogniCrypt_SAST of a Signature object.
* CogniCrypt_SAST reports that the usage pattern does not correspond to the specification within the ORDER block of the CrySL rule for
* Signature
*
*/
public class TypestateErrorExample {
public static void main(String...args) throws GeneralSecurityException {
Signature s = Signature.getInstance("SHA256withRSA");
s.initSign(getPrivateKey());
/**
* The Signature API expects a call to update here. This call supplied the actual data to the signature instance.
* A call such as s.update(data); would resolve this finding.
*/
// s.update(args[0].getBytes());
s.sign();
}
private static PrivateKey getPrivateKey() throws GeneralSecurityException {
KeyPairGenerator kpgen = KeyPairGenerator.getInstance("RSA");
kpgen.initialize(2048);
KeyPair gp = kpgen.generateKeyPair();
return gp.getPrivate();
}
}
| 1,119 | 31 | 136 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/CogniCryptDemoExample/src/main/java/example/fixed/ConstraintErrorExample.java | package example.fixed;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
/**
* This code contains a misuse example CogniCrypt_SAST of a Cipher object.
* CogniCrypt_SAST reports that the string argument to Cipher.getInstance("AES/ECB/PKCS5Padding") does not correspond the CrySL specification.
*
*/
public class ConstraintErrorExample {
public static void main(String...args) throws NoSuchAlgorithmException, NoSuchPaddingException {
Cipher instance = Cipher.getInstance("AES/CBC/PKCS5Padding");
}
}
| 581 | 31.333333 | 143 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/CogniCryptDemoExample/src/main/java/example/fixed/IncompleOperationErrorExample.java | package example.fixed;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.SignatureException;
import javax.crypto.NoSuchPaddingException;
/**
* This code contains a misuse example CogniCrypt_SAST of a Cipher object.
* CogniCrypt_SAST reports that the object is destroyed in an non-accepting state, or in other words the object is not used to fulfill a task.
*
*/
public class IncompleOperationErrorExample {
public static void main(String...args) throws NoSuchAlgorithmException, NoSuchPaddingException, GeneralSecurityException {
Signature instance = Signature.getInstance("SHA256withRSA");
instance.initSign(getPrivateKey());
instance.update(args[0].getBytes());
/**
* The following call is missing, therefore the Signature object is never actually used to compute a Signature.
*/
instance.sign();
IncompleOperationErrorExample ex = new IncompleOperationErrorExample();
ex.doInit();
ex.doUpate();
ex.doSign();
}
private Signature signature;
private void doInit() throws GeneralSecurityException {
signature = Signature.getInstance("SHA256withRSA");
signature.initSign(getPrivateKey());
}
private void doUpate() throws GeneralSecurityException {
signature.update("test".getBytes());
}
private void doSign() throws SignatureException {
/**
* The following call is missing, therefore the Signature object is never actually used to compute a Signature.
*/
signature.sign();
}
private static PrivateKey getPrivateKey() throws GeneralSecurityException {
KeyPairGenerator kpgen = KeyPairGenerator.getInstance("RSA");
kpgen.initialize(2048);
KeyPair gp = kpgen.generateKeyPair();
return gp.getPrivate();
}
}
| 1,878 | 30.316667 | 142 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/CogniCryptDemoExample/src/main/java/example/fixed/PredicateMissingExample.java | package example.fixed;
import java.security.GeneralSecurityException;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
/**
* This code contains a misuse example CogniCrypt_SAST of a Cipher object.
* CogniCrypt_SAST reports that the Cipher instance is initialized (call to init(...,key)) with a key that was not properly generated.
* The key generator is supplied with a key length of 46 (call to init(46)) which is not a correct key length for AES.
* Therefore, the generated secret key will be insecure and transitively the Cipher usage.
*
*/
public class PredicateMissingExample {
public static void main(String...args) throws GeneralSecurityException {
KeyGenerator keygen = KeyGenerator.getInstance("AES");
//CogniCryt_SAST reports an error in the next line saying that the key size is chosen inappropriately.
keygen.init(256);
SecretKey key = keygen.generateKey();
Cipher c = Cipher.getInstance("AES/CBC/PKCS5Padding");
//CogniCryt_SAST reports an error in the next line as the key flowing to this Cipher usage was not generated securely.
c.init(Cipher.ENCRYPT_MODE, key);
byte[] encText = c.doFinal("".getBytes());
}
}
| 1,207 | 39.266667 | 134 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/CogniCryptDemoExample/src/main/java/example/fixed/TypestateErrorExample.java | package example.fixed;
import java.security.GeneralSecurityException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.PrivateKey;
import java.security.Signature;
/**
* This code contains a misuse example CogniCrypt_SAST of a Signature object.
* CogniCrypt_SAST reports that the usage pattern does not correspond to the specification within the ORDER block of the CrySL rule for
* Signature
*
*/
public class TypestateErrorExample {
public static void main(String...args) throws GeneralSecurityException {
Signature s = Signature.getInstance("SHA256withRSA");
s.initSign(getPrivateKey());
/**
* The Signature API expects a call to update here. This call supplied the actual data to the signature instance.
* A call such as s.update(data); would resolve this finding.
*/
s.update(args[0].getBytes());
s.sign();
}
private static PrivateKey getPrivateKey() throws GeneralSecurityException {
KeyPairGenerator kpgen = KeyPairGenerator.getInstance("RSA");
kpgen.initialize(2048);
KeyPair gp = kpgen.generateKeyPair();
return gp.getPrivate();
}
}
| 1,123 | 31.114286 | 136 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/CryptoGuardExamples/brokencrypto/src/main/java/example/brokencrypto/BrokenCryptoABICase1.java | package example.brokencrypto;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
public class BrokenCryptoABICase1 {
public void doCrypto(String crypto) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
SecretKey key = keyGen.generateKey();
Cipher cipher = Cipher.getInstance(crypto);
cipher.init(Cipher.ENCRYPT_MODE, key);
}
public static void main (String [] args) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
BrokenCryptoABICase1 bc = new BrokenCryptoABICase1();
String crypto = "DES/ECB/PKCS5Padding";
bc.doCrypto(crypto);
}
}
| 899 | 36.5 | 123 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/CryptoGuardExamples/brokencrypto/src/main/java/example/brokencrypto/BrokenCryptoABICase2.java | package example.brokencrypto;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
public class BrokenCryptoABICase2 {
public void doCrypto(String crypto) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
KeyGenerator keyGen = KeyGenerator.getInstance("Blowfish");
SecretKey key = keyGen.generateKey();
Cipher cipher = Cipher.getInstance(crypto);
cipher.init(Cipher.ENCRYPT_MODE, key);
}
public static void main (String [] args) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
BrokenCryptoABICase2 bc = new BrokenCryptoABICase2();
String crypto = "Blowfish";
bc.doCrypto(crypto);
}
}
| 892 | 36.208333 | 123 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/CryptoGuardExamples/brokencrypto/src/main/java/example/brokencrypto/BrokenCryptoABICase5.java | package example.brokencrypto;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
public class BrokenCryptoABICase5 {
public static final String DEFAULT_CRYPTO = "DES/ECB/PKCS5Padding";
private static char[] CRYPTO;
private static char[] crypto;
public void doCrypto() throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
KeyGenerator keyGen = KeyGenerator.getInstance("DES");
SecretKey key = keyGen.generateKey();
Cipher cipher = Cipher.getInstance(String.valueOf(crypto));
cipher.init(Cipher.ENCRYPT_MODE, key);
}
private static void go2(){
CRYPTO = DEFAULT_CRYPTO.toCharArray();
}
private static void go3(){
crypto = CRYPTO;
}
public static void main (String [] args) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
BrokenCryptoABICase5 bc = new BrokenCryptoABICase5();
go2();
go3();
bc.doCrypto();
}
}
| 1,164 | 33.264706 | 123 | java |
CryptoAnalysis | CryptoAnalysis-master/CryptoAnalysisTargets/CryptoGuardExamples/brokencrypto/src/main/java/example/brokencrypto/BrokenCryptoBBCase3.java | package example.brokencrypto;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.SecretKey;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
public class BrokenCryptoBBCase3 {
public void go() throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
KeyGenerator keyGen = KeyGenerator.getInstance("RC4");
SecretKey key = keyGen.generateKey();
Cipher cipher = Cipher.getInstance("RC4");
cipher.init(Cipher.ENCRYPT_MODE, key);
}
public static void main (String [] args) throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException {
BrokenCryptoBBCase3 bc = new BrokenCryptoBBCase3();
bc.go();
}
}
| 816 | 34.521739 | 123 | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.