Key k1 = new Key("Shoham's Key", new int[] {0, 5 , 6, 4, 3, 2, 7, 1, 9});
Key encriptionKey = new SecretKeySpec(encriptionKey.getEncoded(), "AES");
String key = "Bar12345Bar12345"; // 128 bit key Key aesKey = new SecretKeySpec(key.getBytes(), "AES"); Cipher cipher = Cipher.getInstance("AES");
for (long i=0; i<1e12; ++i) { Key key = new Key(i); Entry<Key,Value> entry = map.get(key); if (something(key, value)) list.add(entry.getKey()); }
private static Map<Key,Converter<?,?>> converterRegistry; .... static { // ADD static KEYWORD! converterRegistry = new HashMap<Key, Converter<?,?>>(); converterRegistry.put(new Key(String.class, Integer.class), new StringIntegerConverter()); } ...
Map<Key,Key> myMap = new TreeMap<Key,Key>(new SingleFieldMatchComparator()); Key key = new Key(1, 2, 3); myMap.put(key, key); key = new Key(3, 1, 2); myMap.put(key, key); System.out.println(myMap.get(new Key(null, null, null))); System.out.println(myMap.get(new Key(1, null, null))); System.out.println(myMap.get(new Key(null, 2, null))); System.out.println(myMap.get(new Key(null, null, 2))); System.out.println(myMap.get(new Key(2, null, null)));
import java.security.*; byte[] bytesOfMessage = key.getBytes("UTF-8"); MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] b = md.digest(bytesOfMessage); //Returns the SHA 256 hash and converts it into byte // Continue with your code Key secretKey = new SecretKeySpec(b , "AES"); ...
public String getHmacMD5(String privateKey, String input) throws Exception{ String algorithm = "HmacSHA1"; byte[] keyBytes = Base64.decode(privateKey); Key key = new SecretKeySpec(keyBytes, 0, keyBytes.length, algorithm); Mac mac = Mac.getInstance(algorithm); mac.init(key); return Base64.encode(mac.doFinal(input.getBytes())); }
public static void main(String[] args) { Map<Key, String> myMap = new HashMap<>(); Key key = new Key(); key.partOfHashCode = "myHash"; myMap.put(key, "value"); key.partOfHashCode = "mutation of the hashCode of the key"; System.out.println(myMap.get(key)); }
public static void main(String[] args) { Map<Key, String> myMap = new HashMap<>(); Key key = new Key(); key.partOfHashCode = "myHash"; myMap.put(key, "value"); key.notPartOfHashCode = "mutation of the key, but not of its hash/equals definition"; System.out.println(myMap.get(key)); }
byte[] data = Base64 .decodeBase64("McBeY73GQ5fawxIunVKpqUupipeRlt9ntyMRzjbPfTI="); byte[] keyByte = "f931c96c4a4e7e47".getBytes("UTF-8"); byte[] ivByte = "1cc251f602cf49f2".getBytes("UTF-8"); Key key = new SecretKeySpec(keyByte, "AES"); IvParameterSpec iv = new IvParameterSpec(ivByte); Cipher c = Cipher.getInstance("AES/CBC/NoPadding"); c.init(Cipher.DECRYPT_MODE, key, iv); byte[] bval = c.doFinal(data); System.out.println(new String(bval)); // Prints My f awesome test !
public static String decrypt(byte[] keyValue, String ivValue, String encryptedData) throws Exception { Key key = new SecretKeySpec(keyValue, "AES"); byte[] iv = Base64.decode(ivValue.getBytes("UTF-8"), Base64.DEFAULT); byte[] decodedValue = Base64.decode(encryptedData.getBytes("UTF-8"), Base64.DEFAULT); Cipher c = Cipher.getInstance("AES/CBC/PKCS7Padding"); // or PKCS5Padding c.init(Cipher.DECRYPT_MODE, key, new IvParameterSpec(iv)); byte[] decValue = c.doFinal(decodedValue); int firstQuoteIndex = 0; while(decValue[firstQuoteIndex] != (byte)'"') firstQuoteIndex++; return new String(Arrays.copyOfRange(decValue, firstQuoteIndex + 1, decValue.length-2)); }
String secret = "1234567812345678"; Key key = new SecretKeySpec(secret.getBytes(), "AES"); // Encrypt Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] encryptedData = cipher.doFinal("helloworld".getBytes()); // Decrypt cipher.init(Cipher.DECRYPT_MODE, key); byte[] decryptedData = cipher.doFinal(encryptedData); System.out.println(new String(decryptedData, "UTF-8"));
Key key = new Key("test", "some-floats", "float-001"); Bin bin = new Bin("a-float", 3.14159f); this.client.put(null, key, bin); Record record = this.client.get(null, key, "a-float"); double pi = record.getFloat("a-float"); System.out.println("Float:"+pi);
public static void main(String[] args) throws IOException, AWTException { // Move it to here: Key keyObject = new Key(); JFrame.addKeyListener(keyObject); final Robot robot = new Robot(); robot.delay(2000); while(keyObject.spacebarPressed()) { ....