/*package*/ static Secret tryDecrypt(Cipher cipher, byte[] in) { try { String plainText = new String(cipher.doFinal(in), UTF_8); if(plainText.endsWith(MAGIC)) return new Secret(plainText.substring(0,plainText.length()-MAGIC.length())); return null; } catch (GeneralSecurityException e) { return null; // if the key doesn't match with the bytes, it can result in BadPaddingException } }
/** * Attempts to treat the given string first as a cipher text, and if it doesn't work, * treat the given string as the unencrypted secret value. * * <p> * Useful for recovering a value from a form field. */ @Nonnull public static Secret fromString(@CheckForNull String data) { data = Util.fixNull(data); Secret s = decrypt(data); if(s==null) s=new Secret(data); return s; }
return new Secret(text, iv); default: return null;
/*package*/ static Secret tryDecrypt(Cipher cipher, byte[] in) { try { String plainText = new String(cipher.doFinal(in), UTF_8); if(plainText.endsWith(MAGIC)) return new Secret(plainText.substring(0,plainText.length()-MAGIC.length())); return null; } catch (GeneralSecurityException e) { return null; // if the key doesn't match with the bytes, it can result in BadPaddingException } }
/** * Attempts to treat the given string first as a cipher text, and if it doesn't work, * treat the given string as the unencrypted secret value. * * <p> * Useful for recovering a value from a form field. */ @Nonnull public static Secret fromString(@CheckForNull String data) { data = Util.fixNull(data); Secret s = decrypt(data); if(s==null) s=new Secret(data); return s; }
/** * Reverse operation of {@link #getEncryptedValue()}. Returns null * if the given cipher text was invalid. */ public static Secret decrypt(String data) { if(data==null) return null; try { Cipher cipher = getCipher("AES"); cipher.init(Cipher.DECRYPT_MODE, getKey()); String plainText = new String(cipher.doFinal(Base64.decodeBase64(data)), "UTF-8"); if(plainText.endsWith(MAGIC)) return new Secret(plainText.substring(0,plainText.length()-MAGIC.length())); return null; } catch (GeneralSecurityException e) { return null; } catch (UnsupportedEncodingException e) { throw new Error(e); // impossible } catch (IOException e) { return null; } }
/** * Reverse operation of {@link #getEncryptedValue()}. Returns null if the * given cipher text was invalid. */ public static Secret decrypt(String data) { if (data == null) { return null; } try { Cipher cipher = getCipher("AES"); cipher.init(Cipher.DECRYPT_MODE, getKey()); String plainText = new String(cipher.doFinal(Base64.decodeBase64(data)), "UTF-8"); if (plainText.endsWith(MAGIC)) { return new Secret(plainText.substring(0, plainText.length() - MAGIC.length())); } return null; } catch (GeneralSecurityException e) { return null; } catch (UnsupportedEncodingException e) { throw new Error(e); // impossible } catch (IOException e) { return null; } }
/** * Reverse operation of {@link #getEncryptedValue()}. Returns null * if the given cipher text was invalid. */ public static Secret decrypt(String data) { if(data==null) return null; try { Cipher cipher = getCipher("AES"); cipher.init(Cipher.DECRYPT_MODE, getKey()); String plainText = new String(cipher.doFinal(Base64.decode(data.toCharArray())), "UTF-8"); if(plainText.endsWith(MAGIC)) return new Secret(plainText.substring(0,plainText.length()-MAGIC.length())); return null; } catch (GeneralSecurityException e) { return null; } catch (UnsupportedEncodingException e) { throw new Error(e); // impossible } catch (IOException e) { return null; } }
/** * Reverse operation of {@link #getEncryptedValue()}. Returns null * if the given cipher text was invalid. */ public static Secret decrypt(String data) { if(data==null) return null; try { Cipher cipher = getCipher("AES"); cipher.init(Cipher.DECRYPT_MODE, getKey()); String plainText = new String(cipher.doFinal(Base64.decode(data.toCharArray())), "UTF-8"); if(plainText.endsWith(MAGIC)) return new Secret(plainText.substring(0,plainText.length()-MAGIC.length())); return null; } catch (GeneralSecurityException e) { return null; } catch (UnsupportedEncodingException e) { throw new Error(e); // impossible } catch (IOException e) { return null; } }
newHacker.reflect(new Secret());
newHacker.reflect(new Secret());
/** * Attempts to treat the given string first as a cipher text, and if it doesn't work, * treat the given string as the unencrypted secret value. * * <p> * Useful for recovering a value from a form field. * * @return never null */ public static Secret fromString(String data) { data = Util.fixNull(data); Secret s = decrypt(data); if(s==null) s=new Secret(data); return s; }
/** * Attempts to treat the given string first as a cipher text, and if it * doesn't work, treat the given string as the unencrypted secret value. * * <p> Useful for recovering a value from a form field. * * @return never null */ public static Secret fromString(String data) { data = Util.fixNull(data); Secret s = decrypt(data); if (s == null) { s = new Secret(data); } return s; }
/** * Attempts to treat the given string first as a cipher text, and if it doesn't work, * treat the given string as the unencrypted secret value. * * <p> * Useful for recovering a value from a form field. * * @return never null */ public static Secret fromString(String data) { data = Util.fixNull(data); Secret s = decrypt(data); if(s==null) s=new Secret(data); return s; }
/** * Attempts to treat the given string first as a cipher text, and if it doesn't work, * treat the given string as the unencrypted secret value. * * <p> * Useful for recovering a value from a form field. * * @return never null */ public static Secret fromString(String data) { data = Util.fixNull(data); Secret s = decrypt(data); if(s==null) s=new Secret(data); return s; }
return new Secret(text, iv); default: return null;
spawn = new Bonus(this); break; case 3: // spawn Secret spawn = new Secret(this); break;