List of usage examples for org.bouncycastle.crypto.digests SHA1Digest SHA1Digest
public SHA1Digest()
From source file:com.github.horrorho.inflatabledonkey.pcs.xfile.BlockDecrypters.java
License:Open Source License
public static BlockDecrypter create(byte[] key) { BufferedBlockCipher cipher = new BufferedBlockCipher(new CBCBlockCipher(new AESFastEngine())); SHA1Digest digest = new SHA1Digest(); return create(cipher, digest, key); }
From source file:com.github.horrorho.liquiddonkey.cloud.file.FileDecrypter.java
License:Open Source License
/** * Returns a new instance.// w ww . j a va2s. co m * * @return a new instance, not null */ public static FileDecrypter create() { return FileDecrypter.from(new BufferedBlockCipher(new CBCBlockCipher(new AESEngine())), new SHA1Digest()); }
From source file:com.github.horrorho.liquiddonkey.cloud.file.SnapshotDirectory.java
License:Open Source License
static SnapshotDirectory from(Path base, String udidStr, String snapshotIdStr, boolean isFlat, boolean isCombined, String combinedDirectory) { SHA1Digest sha1 = new SHA1Digest(); Path folder = isCombined ? base.resolve(udidStr).resolve(combinedDirectory) : base.resolve(udidStr).resolve(snapshotIdStr); return isFlat ? new FlatSnapshotDirectory(folder, sha1) : new NonFlatSnapshotDirectory(folder, sha1); }
From source file:com.github.jinahya.rfc5849.OAuthSignatureHmacSha1Bc.java
License:Apache License
@Override byte[] get(final byte[] keyBytes, final byte[] baseBytes) throws Exception { final Mac mac = new HMac(new SHA1Digest()); mac.init(new KeyParameter(keyBytes)); mac.update(baseBytes, 0, baseBytes.length); final byte[] output = new byte[mac.getMacSize()]; mac.doFinal(output, 0);/*from ww w. j a va 2 s . c o m*/ return output; }
From source file:com.github.jinahya.rfc5849.OAuthSignatureRsaSha1Bc.java
License:Apache License
@Override byte[] get(final CipherParameters initParam, final byte[] baseBytes) throws Exception { final Signer signer = new RSADigestSigner(new SHA1Digest()); signer.init(true, initParam);/* www. j ava 2s. co m*/ signer.update(baseBytes, 0, baseBytes.length); return signer.generateSignature(); }
From source file:com.google.authenticator.blackberry.AuthenticatorScreen.java
License:Apache License
/** * Computes the one-time PIN given the secret key. * /* w ww .j a v a 2 s.c om*/ * @param secret * the secret key * @return the PIN * @throws GeneralSecurityException * @throws DecodingException * If the key string is improperly encoded. */ public static String computePin(String secret, Long counter) { try { final byte[] keyBytes = Base32String.decode(secret); Mac mac = new HMac(new SHA1Digest()); mac.init(new KeyParameter(keyBytes)); PasscodeGenerator pcg = new PasscodeGenerator(mac); if (counter == null) { // time-based totp return pcg.generateTimeoutCode(); } else { // counter-based hotp return pcg.generateResponseCode(counter.longValue()); } } catch (RuntimeException e) { return "General security exception"; } catch (DecodingException e) { return "Decoding exception"; } }
From source file:com.google.authenticator.blackberry.CheckCodeScreen.java
License:Apache License
static String getCheckCode(String secret) throws Base32String.DecodingException { final byte[] keyBytes = Base32String.decode(secret); Mac mac = new HMac(new SHA1Digest()); mac.init(new KeyParameter(keyBytes)); PasscodeGenerator pcg = new PasscodeGenerator(mac); return pcg.generateResponseCode(0L); }
From source file:com.hanhuy.keepassj.HmacOtp.java
License:Open Source License
public static String Generate(byte[] pbSecret, long uFactor, int uCodeDigits, boolean bAddChecksum, int iTruncationOffset) { byte[] pbText = MemUtil.UInt64ToBytes(uFactor); StrUtil.ArraysReverse(pbText); // Big-Endian HMac hsha1 = new HMac(new SHA1Digest()); KeyParameter key = new KeyParameter(pbSecret); hsha1.init(key);/*from w w w. j a va 2s . com*/ byte[] pbHash = new byte[hsha1.getMacSize()]; hsha1.update(pbText, 0, pbText.length); hsha1.doFinal(pbHash, 0); int uOffset = (int) (pbHash[pbHash.length - 1] & 0xF); if ((iTruncationOffset >= 0) && (iTruncationOffset < (pbHash.length - 4))) uOffset = (int) iTruncationOffset; int uBinary = (int) (((pbHash[uOffset] & 0x7F) << 24) | ((pbHash[uOffset + 1] & 0xFF) << 16) | ((pbHash[uOffset + 2] & 0xFF) << 8) | (pbHash[uOffset + 3] & 0xFF)); int uOtp = (uBinary % vDigitsPower[uCodeDigits]); if (bAddChecksum) uOtp = ((uOtp * 10) + CalculateChecksum(uOtp, uCodeDigits)); int uDigits = (bAddChecksum ? (uCodeDigits + 1) : uCodeDigits); return String.format("%0" + uDigits + "d", uOtp); }
From source file:com.healthmarketscience.jackcess.impl.MSISAMCryptCodecHandler.java
License:Apache License
private static byte[] createPasswordDigest(ByteBuffer buffer, String password, Charset charset) { Digest digest = (((buffer.get(ENCRYPTION_FLAGS_OFFSET) & USE_SHA1) != 0) ? new SHA1Digest() : new MD5Digest()); byte[] passwordBytes = new byte[PASSWORD_LENGTH]; if (password != null) { ByteBuffer bb = ColumnImpl.encodeUncompressedText(password.toUpperCase(), charset); bb.get(passwordBytes, 0, Math.min(passwordBytes.length, bb.remaining())); }//w ww.j a va2 s . co m // Get digest value byte[] digestBytes = hash(digest, passwordBytes, PASSWORD_DIGEST_LENGTH); return digestBytes; }
From source file:com.healthmarketscience.jackcess.impl.office.ECMAStandardEncryptionProvider.java
License:Apache License
@Override protected Digest initDigest() { return new SHA1Digest(); }