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
public class AClassWithOnlyOnePrimitive { | |
private int intValue; | |
public int getIntValue() { | |
return intValue; | |
} | |
public void setIntValue(int intValue) { | |
this.intValue = intValue; | |
} |
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
public class EntryKeyIsVowel implements Predicate<Map.Entry<String,String>> { | |
public boolean apply(Map.Entry<String, String> input) { | |
return input.getKey().matches("^[aeiouAEIOU].*"); | |
} | |
public boolean equals(Object obj) { | |
return this.getClass() == obj.getClass(); | |
} | |
} |
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
public class JCEExampleTest { | |
@Test | |
public void decryptingCiphertextShouldReturnOriginalPlaintext() { | |
assertEquals("Original Plaintext", decrypt(encrypt("Original Plaintext"))); | |
} | |
private String decrypt(String cipherText) { | |
return null; | |
} |
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
public class JCEExampleTest { | |
@Test | |
public void decryptingCiphertextShouldReturnOriginalPlaintext() { | |
assertEquals("Original Plaintext", decrypt(encrypt("Original Plaintext"))); | |
} | |
private String decrypt(String cipherText) { | |
return cipherText; | |
} |
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
byte[] sessionKey = null; | |
byte[] iv = new byte[] { 0x7F, 0x6E, 0x5D, 0x4C, 0x3B, 0x2A, 0x19, 0x08 }; | |
byte[] ciphertext = null; | |
Cipher cipher; | |
try { | |
KeyGenerator kGen = KeyGenerator.getInstance("AES"); | |
kGen.init(128); | |
sessionKey = kGen.generateKey().getEncoded(); | |
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); | |
//You can use ENCRYPT_MODE or DECRYPT_MODE |
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
private String encrypt(String plainText) { | |
byte[] sessionKey = null; //Where you get this from is beyond the scope of this post | |
byte[] iv = null; //Ditto | |
byte[] ciphertext = null; | |
Cipher cipher; | |
try { | |
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); | |
//You can use ENCRYPT_MODE or DECRYPT_MODE | |
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(sessionKey, "AES"), new IvParameterSpec(iv)); |
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
public class JCEExampleTest { | |
@Test | |
public void decryptingCiphertextShouldReturnOriginalPlaintext() { | |
} | |
} | |
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
@Test | |
public void decryptingCiphertextShouldReturnOriginalPlaintext() { | |
assertEquals("Original Plaintext", decrypt(encrypt("Original Plaintext"))); | |
} | |
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
public class JCEExampleTest { | |
private byte[] sessionKey = null; | |
private final byte[] iv = new byte[] { 0x7F, 0x6E, 0x5D, 0x4C, 0x3B, 0x2A, 0x19, 0x08, | |
0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 }; | |
@Test | |
public void decryptingCiphertextShouldReturnOriginalPlaintext() { | |
assertEquals("Original Plaintext", decrypt(encrypt("Original Plaintext"))); | |
} |
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
private String decrypt(String cipherText) { | |
byte[] plaintext = null; | |
Cipher cipher; | |
try { | |
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); | |
//You can use ENCRYPT_MODE or DECRYPT_MODE | |
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(sessionKey, "AES"), new IvParameterSpec(iv)); | |
plaintext = cipher.doFinal(new sun.misc.BASE64Decoder().decodeBuffer(cipherText)); | |
} catch (NoSuchAlgorithmException e) { |
OlderNewer