List of usage examples for org.bouncycastle.crypto.digests SHA1Digest SHA1Digest
public SHA1Digest()
From source file:com.identarian.infocard.opensso.rp.InfocardClaims.java
License:CDDL license
public static String friendlyPPID(String ppid) { // code map//ww w. j a va 2 s . c o m char[] ss = { 'Q', 'L', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'M', 'N', 'P', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; // base 64 decoding byte[] b = Base64.decode(ppid.getBytes()); // sha1 decoding SHA1Digest digEng = new SHA1Digest(); digEng.update(b, 0, b.length); byte[] b1 = new byte[digEng.getDigestSize()]; digEng.doFinal(b1, 0); // convert the bytes to ints StringBuffer sb = new StringBuffer(); for (int i = 0; i < 10; i++) { int ii = byte2int(b1[i]) % 32; if (i == 3 || i == 7) { sb.append("-"); } // mapping of the int to mapping code sb.append(ss[ii]); } return sb.toString(); }
From source file:com.injoit.examplechat.util.Util.java
License:Open Source License
/** * Returns a SHA1 digest of the given string, in hex values lowercase. * @param _str//from w ww . j ava2 s. co m */ public static String sha1(String _str) { String res; SHA1Digest digest = new SHA1Digest(); String tmp = _str; byte in[] = tmp.getBytes(); digest.update(in, 0, in.length); byte out[] = new byte[20]; digest.doFinal(out, 0); // builds the hex string (lowercase) res = ""; tmp = ""; // tmp = two characters to append to the hex string for (int i = 0; i < 20; i++) { int unsigned = out[i]; if (out[i] < 0) { unsigned += 256; } tmp = Integer.toHexString(unsigned); if (tmp.length() == 1) { tmp = "0" + tmp; } res = res + tmp; } return res; }
From source file:com.injoit.examplechat.util.Util.java
License:Open Source License
/** * Returns a SHA1 digest of the given array of bytes, in hex values lowercase. * @param _str/*w ww .j a v a 2s.co m*/ */ public static String sha1(byte[] in) { String res; SHA1Digest digest = new SHA1Digest(); String tmp; digest.update(in, 0, in.length); byte out[] = new byte[20]; digest.doFinal(out, 0); // builds the hex string (lowercase) res = ""; tmp = ""; // tmp = two characters to append to the hex string for (int i = 0; i < 20; i++) { int unsigned = out[i]; if (out[i] < 0) { unsigned += 256; } tmp = Integer.toHexString(unsigned); if (tmp.length() == 1) { tmp = "0" + tmp; } res = res + tmp; } return res; }
From source file:com.johnhunsley.events.domain.Hash.java
License:Apache License
/** * <p>//ww w.jav a 2 s .c o m * Creates a new Hash object implementing the encryption algorithm denoted by the given type. * Will default to SHA1 * </p> * @param type */ public Hash(final int type) { switch (type) { case SHA1_TYPE: digest = new SHA1Digest(); break; case MD5_TYPE: digest = new MD5Digest(); break; default: digest = new SHA1Digest(); } }
From source file:com.joyent.manta.client.crypto.SupportedHmacsLookupMap.java
License:Open Source License
/** * Wraps a getInstance call as a {@link Supplier} so that we can return a * new HMAC instance for every value of this map. * * @param algorithm algorithm to instantiate HMAC instance as * @return supplier wrapping getInstance call to get HMAC instance */// ww w .j a v a 2s . c o m private static Supplier<HMac> hmacSupplierByName(final String algorithm) { return () -> { if (algorithm.equalsIgnoreCase("HmacMD5")) { return new HMac(new FastMD5Digest()); } else if (algorithm.equalsIgnoreCase("HmacSHA1")) { return new HMac(new SHA1Digest()); } else if (algorithm.equalsIgnoreCase("HmacSHA256")) { return new HMac(new SHA256Digest()); } else if (algorithm.equalsIgnoreCase("HmacSHA384")) { return new HMac(new SHA384Digest()); } else if (algorithm.equalsIgnoreCase("HmacSHA512")) { return new HMac(new SHA512Digest()); } else { String msg = String.format("Hmac algorithm [%s] not supported", algorithm); throw new MantaClientEncryptionException(msg); } }; }
From source file:com.jrdp.core.encryption.RC4Session.java
License:Apache License
/** * Generates a Salted MAC for the current packet * @see <a href=http://msdn.microsoft.com/en-us/library/cc240789(v=PROT.10).aspx> * 5.3.6.1.1 Salted MAC Generation</a> *//*from w ww . j a v a2s . c o m*/ @Override public byte[] createMac(byte[] data) { SHA1Digest sha1 = new SHA1Digest(); sha1.update(macKey, 0, macKey.length); sha1.update(Constants.pad36, 0, Constants.pad36.length); byte[] length = new byte[4]; BitManip.setLittleEndian(length, 0, data.length); sha1.update(length, 0, length.length); sha1.update(data, 0, data.length); byte[] sha1Digest = new byte[Constants.SHA1_DIGEST_LENGTH]; sha1.doFinal(sha1Digest, 0); MD5Digest md5 = new MD5Digest(); md5.update(macKey, 0, macKey.length); md5.update(Constants.pad5c, 0, Constants.pad5c.length); md5.update(sha1Digest, 0, sha1Digest.length); byte[] md5Digest = new byte[Constants.MD5_DIGEST_LENGTH]; md5.doFinal(md5Digest, 0); byte[] mac = new byte[8]; System.arraycopy(md5Digest, 0, mac, 0, 8); return mac; }
From source file:com.jrdp.core.encryption.RC4Session.java
License:Apache License
private byte[] updateRc4Key(byte[] originalKey, byte[] currentKey) { int keySize = 0; switch (encryptionMethod) { case Constants.ENCRYPTION_128BIT: keySize = 16;//from w w w . j ava2 s. co m break; case Constants.ENCRYPTION_40BIT: case Constants.ENCRYPTION_56BIT: keySize = 8; break; case Constants.ENCRYPTION_NONE: case Constants.ENCRYPTION_FIPS: //Should never happen... return null; } SHA1Digest sha1 = new SHA1Digest(); sha1.update(originalKey, 0, keySize); sha1.update(Constants.pad36, 0, Constants.pad36.length); sha1.update(currentKey, 0, currentKey.length); byte[] shaComponent = new byte[Rdp.SHA1_DIGEST_LENGTH]; sha1.doFinal(shaComponent, 0); //StringManip.print(shaComponent, "SHA1:"); MD5Digest md5 = new MD5Digest(); md5.update(originalKey, 0, keySize); md5.update(Constants.pad5c, 0, Constants.pad5c.length); md5.update(shaComponent, 0, shaComponent.length); byte[] tempKey = new byte[Rdp.MD5_DIGEST_LENGTH]; md5.doFinal(tempKey, 0); //StringManip.print(tempKey, "MD5:"); RC4Engine rc4 = new RC4Engine(); if (keySize == 16) { byte[] newKey = new byte[tempKey.length]; rc4.init(true, new KeyParameter(tempKey)); rc4.processBytes(tempKey, 0, tempKey.length, newKey, 0); return newKey; } else { byte[] newKey = new byte[8]; byte[] smallerTmpKey = new byte[8]; System.arraycopy(tempKey, 0, smallerTmpKey, 0, 8); rc4.init(true, new KeyParameter(smallerTmpKey)); rc4.processBytes(smallerTmpKey, 0, 8, newKey, 0); newKey[0] = (byte) 0xd1; if (encryptionMethod == Constants.ENCRYPTION_40BIT) { newKey[1] = 0x26; newKey[2] = (byte) 0x9e; } return newKey; } }
From source file:com.jrdp.core.remote.rdp.Secure.java
License:Apache License
private static byte[] saltedHash(byte[] clientRandom, byte[] serverRandom, byte[] salt, byte[][] in) { byte[] saltedHash = new byte[MD5_DIGEST_LENGTH * in.length]; for (int i = 0; i < in.length; i++) { SHA1Digest sha1 = new SHA1Digest(); sha1.update(in[i], 0, in[i].length); sha1.update(salt, 0, salt.length); sha1.update(clientRandom, 0, clientRandom.length); sha1.update(serverRandom, 0, serverRandom.length); byte[] sha1Digest = new byte[SHA1_DIGEST_LENGTH]; sha1.doFinal(sha1Digest, 0);/*from w w w. j a v a 2s. c o m*/ MD5Digest md5 = new MD5Digest(); md5.update(salt, 0, salt.length); md5.update(sha1Digest, 0, sha1Digest.length); byte[] md5Digest = new byte[MD5_DIGEST_LENGTH]; md5.doFinal(md5Digest, 0); System.arraycopy(md5Digest, 0, saltedHash, i * MD5_DIGEST_LENGTH, MD5_DIGEST_LENGTH); } return saltedHash; }
From source file:com.licel.jcardsim.crypto.AsymmetricSignatureImpl.java
License:Apache License
public AsymmetricSignatureImpl(byte algorithm) { this.algorithm = algorithm; isRecovery = false;/* w w w. j a v a2s . c o m*/ switch (algorithm) { case ALG_RSA_SHA_ISO9796: engine = new ISO9796d2Signer(new RSAEngine(), new SHA1Digest()); break; case ALG_RSA_SHA_ISO9796_MR: engine = new ISO9796d2Signer(new RSAEngine(), new SHA1Digest()); isRecovery = true; break; case ALG_RSA_SHA_PKCS1: engine = new RSADigestSigner(new SHA1Digest()); break; case ALG_RSA_MD5_PKCS1: engine = new RSADigestSigner(new MD5Digest()); break; case ALG_RSA_RIPEMD160_ISO9796: engine = new ISO9796d2Signer(new RSAEngine(), new RIPEMD160Digest()); break; case ALG_RSA_RIPEMD160_PKCS1: engine = new RSADigestSigner(new RIPEMD160Digest()); break; case ALG_ECDSA_SHA: engine = new DSADigestSigner(new ECDSASigner(), new SHA1Digest()); break; } }
From source file:com.licel.jcardsim.crypto.KeyAgreementImpl.java
License:Apache License
public KeyAgreementImpl(byte algorithm) { this.algorithm = algorithm; switch (algorithm) { case ALG_EC_SVDP_DH: engine = new ECDHBasicAgreement(); break;//from w w w . j a va 2 s . co m case ALG_EC_SVDP_DHC: engine = new ECDHCBasicAgreement(); break; default: CryptoException.throwIt(CryptoException.NO_SUCH_ALGORITHM); break; } digestEngine = new SHA1Digest(); }