List of usage examples for org.bouncycastle.crypto.digests SHA1Digest SHA1Digest
public SHA1Digest()
From source file:com.licel.jcardsim.crypto.MessageDigestImpl.java
License:Apache License
public MessageDigestImpl(byte algorithm) { this.algorithm = algorithm; blockSize = 64;/* w w w . j ava2s . c om*/ componentStartIdx = 1; switch (algorithm) { case ALG_SHA: engine = new SHA1Digest(); digestClass = engine.getClass(); break; case ALG_MD5: engine = new MD5Digest(); digestClass = engine.getClass(); break; case ALG_RIPEMD160: engine = new RIPEMD160Digest(); digestClass = engine.getClass(); componentStartIdx = 0; break; case ALG_SHA_256: engine = new SHA256Digest(); digestClass = engine.getClass(); break; case ALG_SHA_384: engine = new SHA384Digest(); blockSize = 128; byteCountFieldName = "byteCount1"; digestClass = engine.getClass().getSuperclass(); break; case ALG_SHA_512: engine = new SHA512Digest(); blockSize = 128; byteCountFieldName = "byteCount1"; digestClass = engine.getClass().getSuperclass(); break; default: CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM); break; } componentSize = (byte) (blockSize == 64 ? 4 : 8); componentCount = (byte) (engine.getDigestSize() / componentSize); }
From source file:com.licel.jcardsim.crypto.RandomDataImpl.java
License:Apache License
public RandomDataImpl() { engine = new DigestRandomGenerator(new SHA1Digest()); }
From source file:com.licel.jcardsim.crypto.SymmetricSignatureImpl.java
License:Apache License
public void init(Key theKey, byte theMode, byte[] bArray, short bOff, short bLen) throws CryptoException { if (theKey == null) { CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); }/*from www . j a va 2 s. co m*/ if (!theKey.isInitialized()) { CryptoException.throwIt(CryptoException.UNINITIALIZED_KEY); } if (!(theKey instanceof SymmetricKeyImpl)) { CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); } CipherParameters cipherParams = null; BlockCipher cipher = ((SymmetricKeyImpl) theKey).getCipher(); if (bArray == null) { cipherParams = ((SymmetricKeyImpl) theKey).getParameters(); } else { if (bLen != cipher.getBlockSize()) { CryptoException.throwIt(CryptoException.ILLEGAL_VALUE); } cipherParams = new ParametersWithIV(((SymmetricKeyImpl) theKey).getParameters(), bArray, bOff, bLen); } switch (algorithm) { case ALG_DES_MAC4_NOPAD: engine = new CBCBlockCipherMac(cipher, 32, null); break; case ALG_DES_MAC8_NOPAD: engine = new CBCBlockCipherMac(cipher, 64, null); break; case ALG_DES_MAC4_ISO9797_M1: engine = new CBCBlockCipherMac(cipher, 32, new ZeroBytePadding()); break; case ALG_DES_MAC8_ISO9797_M1: engine = new CBCBlockCipherMac(cipher, 64, new ZeroBytePadding()); break; case ALG_DES_MAC4_ISO9797_M2: engine = new CBCBlockCipherMac(cipher, 32, new ISO7816d4Padding()); break; case ALG_DES_MAC8_ISO9797_M2: engine = new CBCBlockCipherMac(cipher, 64, new ISO7816d4Padding()); break; case ALG_DES_MAC8_ISO9797_1_M2_ALG3: engine = new ISO9797Alg3Mac(new DESEngine(), 64, new ISO7816d4Padding()); break; case ALG_DES_MAC4_PKCS5: engine = new CBCBlockCipherMac(cipher, 32, new PKCS7Padding()); break; case ALG_DES_MAC8_PKCS5: engine = new CBCBlockCipherMac(cipher, 64, new PKCS7Padding()); break; case ALG_AES_MAC_128_NOPAD: engine = new CBCBlockCipherMac(cipher, 128, null); break; case ALG_HMAC_SHA1: engine = new HMac(new SHA1Digest()); break; case ALG_HMAC_SHA_256: engine = new HMac(new SHA256Digest()); break; case ALG_HMAC_SHA_384: engine = new HMac(new SHA384Digest()); break; case ALG_HMAC_SHA_512: engine = new HMac(new SHA512Digest()); break; case ALG_HMAC_MD5: engine = new HMac(new MD5Digest()); break; case ALG_HMAC_RIPEMD160: engine = new HMac(new RIPEMD160Digest()); break; default: CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM); break; } engine.init(cipherParams); isInitialized = true; }
From source file:com.nokia.xfolite.xforms.xpath.XFormsCoreFunctionLibrary.java
License:Open Source License
public static String digest_function(String s, String method, String encoding) { //#debug info System.out.println("Digest function invoked with params(" + s + "," + method + "," + encoding + ")"); Digest digest = null;//www . j a v a 2 s . co m Encoder encoder = null; if (encoding.equals("base64")) { encoder = new Base64Encoder(); } else if (encoding.equals("hex")) { encoder = new HexEncoder(); } if (method.equals("SHA-1")) { digest = new SHA1Digest(); } else if (method.equals("SHA-256")) { digest = new SHA256Digest(); } else if (method.equals("SHA-512")) { digest = new SHA512Digest(); } else if (method.equals("MD5")) { digest = new MD5Digest(); } if (encoder == null) { throw new XPathException(XPathException.TYPE_ERR, "XForms function digest() only supports hex and base64 encoding."); } if (digest == null) { throw new XPathException(XPathException.TYPE_ERR, "XForms function digest() only supports MD5, SHA-1, SHA-256 and SHA-512 digests."); } int len = s.length(); for (int i = 0; i < len; i++) { digest.update((byte) s.charAt(i)); // FIXME: Better not use non-ASCII characters! } byte[] data = new byte[digest.getDigestSize()]; digest.doFinal(data, 0); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try { encoder.encode(data, 0, data.length, bOut); } catch (IOException e) { throw new XPathException(XPathException.TYPE_ERR, "Exception when encoding digest: " + e); } byte[] out = bOut.toByteArray(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < out.length; i++) { sb.append((char) out[i]); // This works fine, neither hex nor base64 encodings produce } return sb.toString(); }
From source file:com.stg.crypto.CryptoHelper.java
License:Open Source License
/** * Returns the SHA1 checksum for the given bytes. * @param bytes against which the SHA1 checksum is to be generated. * @return String representation of the SHA1 checksum. *///from w w w . j a v a2 s . com public static String generateSHA1Checksum(byte[] bytes) { return generateChecksum(new SHA1Digest(), bytes); }
From source file:com.stg.crypto.CryptoHelper.java
License:Open Source License
/** * This reads the stream fully to generate the SHA1 checksum. * This may lead to OutOfMemory as the stream is fully read before generating the checksum. * Use {@link IODigestUtility} to read large streams and generate checksums. * //ww w .j ava 2 s.com * @param is input steam * @return digest generated using SHA1. * @throws IOException * @see IODigestUtility */ public static String generateSHA1Checksum(InputStream is) throws IOException { byte[] bytes = IOUtils.toByteArray(is); return generateChecksum(new SHA1Digest(), bytes); }
From source file:com.stg.crypto.IODigestUtility.java
License:Open Source License
/** * Helper method that returns an IODigestUtility configured for SHA1 Digest. * /* www .j av a 2s .co m*/ * @return IODigestUtility */ public static DigestInputStream getSHA1IODigest(InputStream is) { return wrapDigestInputStream(new SHA1Digest(), is); }
From source file:com.substanceofcode.twitter.XAuth.java
License:Apache License
public String getSignature(String message, String key) { try {/*from w w w. j av a 2s . co m*/ HMac m = new HMac(new SHA1Digest()); m.init(new KeyParameter(key.getBytes("UTF-8"))); byte[] bytes = message.getBytes("UTF-8"); m.update(bytes, 0, bytes.length); byte[] mac = new byte[m.getMacSize()]; m.doFinal(mac, 0); String signature = new Base64().encode(mac); return signature; } catch (UnsupportedEncodingException ex) { ex.printStackTrace(); } return null; }
From source file:com.sun.midp.crypto.SHA.java
License:Open Source License
/** Create SHA digest object. */ SHA() { impl = new SHA1Digest(); }
From source file:com.symbian.security.Pkcs12Pbe.java
License:Open Source License
public Pkcs12Pbe() { pgen = new PKCS12ParametersGenerator(new SHA1Digest()); }