public static byte[] objectToByteArray (Object o) throws ByteException { return objectsToByteArray(new Object[] { o }); }
public static String digestPassword (String pass) throws NoSuchAlgorithmException { java.security.MessageDigest digest = java.security.MessageDigest .getInstance(DIGEST_ALGORITHM); digest.update(pass.getBytes()); return ByteUtils.toString(digest.digest()); }
public MockValue (final java.io.InputStream val) throws JcrException { super(); this.type = PropertyType.BINARY; try { final java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); ByteUtils.copy(val, baos, 1024); this.value = baos.toByteArray(); } catch (final java.io.IOException ie) { throw new JcrException ("failed to fetch data from input stream", ie); } }
public boolean verify (RsaKey publicKey) throws CryptoException { try { Signature sig = Signature.getInstance("MD5withRSA"); sig.initVerify((java.security.PublicKey)publicKey.assembleRealKey()); sig.update(ByteUtils.objectToByteArray(this.object)); return sig.verify(ByteUtils.fromString(this.signature)); } catch (Exception e) { throw new CryptoException ("Failed to verify signed object", e); } }
public SignedObject (final java.io.Serializable object, final RsaKey privateKey) throws CryptoException { super(); this.object = object; try { Signature sig = Signature.getInstance("MD5withRSA"); sig.initSign ((java.security.PrivateKey)privateKey.assembleRealKey()); sig.update (ByteUtils.objectToByteArray(this.object)); this.signature = ByteUtils.toString(sig.sign()); } catch (Exception e) { throw new CryptoException ("Failed to sign object", e); } }
public static byte[] fromString (String s) throws NumberFormatException { java.io.ByteArrayOutputStream os = new java.io.ByteArrayOutputStream(); String currentByte = ""+s.charAt(0); for (int i=1; i<s.length(); i++) { char c = s.charAt(i); if (c == '+' || c == '-') { os.write(toByte(currentByte)); currentByte = ""+c; continue; } currentByte += c; } os.write(toByte(currentByte)); return os.toByteArray(); }
out = new java.io.FileOutputStream(destinationPath); ByteUtils.copy(in, out, 1024);
protected byte[] decodeByteArray () throws BeanCoderException { final java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); final java.io.InputStream is = this.currentProperty() .getValue().getStream(); try { ByteUtils.copy(is, baos, 1024); } catch (final Throwable t) { throw new BeanCoderException ("Failed to decode byte array for '"+this.currentItemName+ "' out of stream", t); } return baos.toByteArray(); }
/** * (not very much used these days) */ public static String getMd5Digest (byte[] data) { java.security.MessageDigest digest = null; try { digest = java.security.MessageDigest.getInstance("MD5"); } catch (java.security.NoSuchAlgorithmException nsae) { log.warn("cannot compute MD5 digest", nsae); return null; } digest.update(data); return ByteUtils.toString(digest.digest()); }