Skip to content

Commit

Permalink
Merge pull request #662 from CROSSINGTUD/fix/issue-69
Browse files Browse the repository at this point in the history
Add test case from #69
  • Loading branch information
schlichtig authored Jul 5, 2024
2 parents 5acb393 + 0b205b1 commit e57b0ed
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public void reportedIssues() {
setErrorsCount("<issue70.ClientProtocolDecoder: byte[] decryptAES(byte[])>", ConstraintError.class, 1);
setErrorsCount("<issue70.ClientProtocolDecoder: byte[] decryptAES(byte[])>", RequiredPredicateError.class, 3);

setErrorsCount("<issue69.Issue69: void encryptByPublicKey(java.lang.String)>", IncompleteOperationError.class, 1);
setErrorsCount("<issue69.Issue69: void encryptByPublicKey(java.lang.String)>", RequiredPredicateError.class, 4);

// TODO toCharArray() is not currently not considered when evaluating NeverTypeOfErrors
setErrorsCount("<issue68.AESCryptor: byte[] getKey(java.lang.String)>", NeverTypeOfError.class, 0);
setErrorsCount("<issue68.AESCryptor: byte[] getKey(java.lang.String)>", RequiredPredicateError.class, 3);
Expand Down
8 changes: 8 additions & 0 deletions CryptoAnalysisTargets/ReportedIssues/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,12 @@
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package issue69;

import org.apache.commons.codec.binary.Base64;

import javax.crypto.Cipher;
import java.security.Key;
import java.security.KeyFactory;
import java.security.spec.X509EncodedKeySpec;

public class Issue69 {

private static final String KEY_ALGORITHM = "RSA";

public void encryptByPublicKey(String publicKey) throws Exception {
byte[] keyBytes = new Base64().decode(publicKey.getBytes());
X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
Key publicK = keyFactory.generatePublic(x509KeySpec);

Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());

// RequiredPredicateError because no predicate is ensured on 'keyBytes'
cipher.init(Cipher.ENCRYPT_MODE, publicK);
}
}

0 comments on commit e57b0ed

Please sign in to comment.