-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #395 from panoob/develop
fix wrong arrayLocal in extractSootArray for HardcodedError
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>example</groupId> | ||
<artifactId>PBEKeySpec-TP</artifactId> | ||
<packaging>jar</packaging> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<name>PBEKeySpec-TP</name> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.8.0</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
36 changes: 36 additions & 0 deletions
36
CryptoAnalysisTargets/HardcodedTestExamples/src/main/java/example/TrueNegative.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import javax.crypto.SecretKeyFactory; | ||
import javax.crypto.spec.PBEKeySpec; | ||
import java.security.SecureRandom; | ||
|
||
public class TrueNegative { | ||
|
||
public void trueNegative() { | ||
byte[] pass = new byte[256]; | ||
byte[] salt = new byte[256]; | ||
|
||
SecureRandom secureRandom = new SecureRandom(); | ||
secureRandom.nextBytes(salt); | ||
secureRandom.nextBytes(pass); | ||
|
||
// convert byte array to char array | ||
char[] passwd = new char[pass.length]; | ||
for(int i=0; i < pass.length; i++){ | ||
passwd[i] = (char) (pass[i]&0xff); | ||
} | ||
|
||
byte[] key = getKey(passwd, salt, 10000, 256); | ||
} | ||
|
||
public static byte[] getKey(char[] pass, byte[] salt, int iterations, int size) { | ||
// generate a key via a PBEKeySpec | ||
try{ | ||
PBEKeySpec spec = new PBEKeySpec(pass, salt, iterations, size); | ||
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); | ||
byte[] key = skf.generateSecret(spec).getEncoded(); | ||
spec.clearPassword(); | ||
return key; | ||
} catch (Exception e) { | ||
} | ||
return null; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
CryptoAnalysisTargets/HardcodedTestExamples/src/main/java/example/TruePositive.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import javax.crypto.SecretKeyFactory; | ||
import javax.crypto.spec.PBEKeySpec; | ||
import java.security.SecureRandom; | ||
|
||
public class TruePositive { | ||
|
||
public void truePositive() { | ||
char[] passwd = {'t','h','i','s'}; | ||
byte[] salt = new byte[256]; | ||
|
||
SecureRandom secureRandom = new SecureRandom(); | ||
secureRandom.nextBytes(salt); | ||
|
||
byte[] key = getKey(passwd, salt, 10000, 256); | ||
} | ||
|
||
public static byte[] getKey(char[] pass, byte[] salt, int iterations, int size) { | ||
// generate a key via a PBEKeySpec | ||
try{ | ||
PBEKeySpec spec = new PBEKeySpec(pass, salt, iterations, size); | ||
SecretKeyFactory skf = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256"); | ||
byte[] key = skf.generateSecret(spec).getEncoded(); | ||
spec.clearPassword(); | ||
return key; | ||
} catch (Exception e) { | ||
} | ||
return null; | ||
} | ||
} |