org.jclouds.crypto
Class CryptoStreams

java.lang.Object
  extended by org.jclouds.crypto.CryptoStreams

@Beta
public class CryptoStreams
extends Object

functions related to but not in ByteStreams

Author:
Adrian Cole

Constructor Summary
CryptoStreams()
           
 
Method Summary
static String base64(byte[] in)
           
static byte[] base64(String in)
           
static byte[] base64Decode(com.google.common.io.InputSupplier<? extends InputStream> supplier)
          Computes and returns the unencoded value for an input stream which is encoded in Base64.
static String base64Encode(com.google.common.io.InputSupplier<? extends InputStream> supplier)
          Computes and returns the base64 value for a supplied input stream.
static byte[] digest(com.google.common.io.InputSupplier<? extends InputStream> supplier, MessageDigest md)
          Computes and returns the Digest value for a supplied input stream.
static String hex(byte[] in)
           
static byte[] hex(String s)
           
static byte[] hexDecode(com.google.common.io.InputSupplier<? extends InputStream> supplier)
          Computes and returns the unencoded value for an input stream which is encoded in hex.
static String hexEncode(com.google.common.io.InputSupplier<? extends InputStream> supplier)
          Computes and returns the hex value for a supplied input stream.
static byte[] mac(com.google.common.io.InputSupplier<? extends InputStream> supplier, Mac mac)
          Computes and returns the MAC value for a supplied input stream.
static String macBase64(com.google.common.io.InputSupplier<? extends InputStream> supplier, Mac mac)
          Computes and returns the MAC value for a supplied input stream.
static byte[] md5(byte[] in)
           
static byte[] md5(com.google.common.io.InputSupplier<? extends InputStream> supplier)
          Computes and returns the MD5 value for a supplied input stream.
static String md5Base64(com.google.common.io.InputSupplier<? extends InputStream> supplier)
           
static String md5Hex(com.google.common.io.InputSupplier<? extends InputStream> supplier)
           
static byte[] sha1(byte[] in)
           
static byte[] sha1(com.google.common.io.InputSupplier<? extends InputStream> supplier)
          Computes and returns the SHA1 value for a supplied input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CryptoStreams

public CryptoStreams()
Method Detail

hex

public static String hex(byte[] in)

hex

public static byte[] hex(String s)

base64

public static String base64(byte[] in)

base64

public static byte[] base64(String in)

md5Hex

public static String md5Hex(com.google.common.io.InputSupplier<? extends InputStream> supplier)
                     throws IOException
Throws:
IOException
See Also:
md5(com.google.common.io.InputSupplier), hex(byte[])

md5Base64

public static String md5Base64(com.google.common.io.InputSupplier<? extends InputStream> supplier)
                        throws IOException
Throws:
IOException
See Also:
md5(com.google.common.io.InputSupplier), base64(byte[])

macBase64

public static String macBase64(com.google.common.io.InputSupplier<? extends InputStream> supplier,
                               Mac mac)
                        throws IOException
Computes and returns the MAC value for a supplied input stream. The mac object is reset when this method returns successfully.

Parameters:
supplier - the input stream factory
mac - the mac object
Returns:
the result of Mac.doFinal() after updating the mac object with all of the bytes in the stream and encoding in Base64
Throws:
IOException - if an I/O error occurs

digest

public static byte[] digest(com.google.common.io.InputSupplier<? extends InputStream> supplier,
                            MessageDigest md)
                     throws IOException
Computes and returns the Digest value for a supplied input stream. The digest object is reset when this method returns successfully.

Parameters:
supplier - the input stream factory
md - the digest object
Returns:
the result of MessageDigest.digest() after updating the digest object with all of the bytes in the stream
Throws:
IOException - if an I/O error occurs

sha1

public static byte[] sha1(com.google.common.io.InputSupplier<? extends InputStream> supplier)
                   throws IOException
Computes and returns the SHA1 value for a supplied input stream. A digest object is created and disposed of at runtime, consider using digest(com.google.common.io.InputSupplier, java.security.MessageDigest) to be more efficient.

Parameters:
supplier - the input stream factory
Returns:
the result of MessageDigest.digest() after updating the sha1 object with all of the bytes in the stream
Throws:
IOException - if an I/O error occurs

sha1

public static byte[] sha1(byte[] in)

md5

public static byte[] md5(com.google.common.io.InputSupplier<? extends InputStream> supplier)
                  throws IOException
Computes and returns the MD5 value for a supplied input stream. A digest object is created and disposed of at runtime, consider using digest(com.google.common.io.InputSupplier, java.security.MessageDigest) to be more efficient.

Parameters:
supplier - the input stream factory
Returns:
the result of MessageDigest.digest() after updating the md5 object with all of the bytes in the stream
Throws:
IOException - if an I/O error occurs

md5

public static byte[] md5(byte[] in)

mac

public static byte[] mac(com.google.common.io.InputSupplier<? extends InputStream> supplier,
                         Mac mac)
                  throws IOException
Computes and returns the MAC value for a supplied input stream. The mac object is reset when this method returns successfully.

Parameters:
supplier - the input stream factory
mac - the mac object
Returns:
the result of Mac.doFinal() after updating the mac object with all of the bytes in the stream
Throws:
IOException - if an I/O error occurs

base64Encode

public static String base64Encode(com.google.common.io.InputSupplier<? extends InputStream> supplier)
                           throws IOException
Computes and returns the base64 value for a supplied input stream.

Parameters:
supplier - the input stream factory
Returns:
the result of base 64 encoding all of the bytes in the stream
Throws:
IOException - if an I/O error occurs

base64Decode

public static byte[] base64Decode(com.google.common.io.InputSupplier<? extends InputStream> supplier)
                           throws IOException
Computes and returns the unencoded value for an input stream which is encoded in Base64.

Parameters:
supplier - the input stream factory
Returns:
the result of base 64 decoding all of the bytes in the stream
Throws:
IOException - if an I/O error occurs

hexEncode

public static String hexEncode(com.google.common.io.InputSupplier<? extends InputStream> supplier)
                        throws IOException
Computes and returns the hex value for a supplied input stream.

Parameters:
supplier - the input stream factory
Returns:
the result of hex encoding all of the bytes in the stream
Throws:
IOException - if an I/O error occurs

hexDecode

public static byte[] hexDecode(com.google.common.io.InputSupplier<? extends InputStream> supplier)
                        throws IOException
Computes and returns the unencoded value for an input stream which is encoded in hex.

Parameters:
supplier - the input stream factory
Returns:
the result of hex decoding all of the bytes in the stream
Throws:
IOException - if an I/O error occurs


Copyright © 2009-2011 jclouds. All Rights Reserved.