List of usage examples for org.bouncycastle.crypto.digests SHA384Digest SHA384Digest
public SHA384Digest()
From source file:bluecrystal.service.service.SignVerifyService.java
License:Open Source License
private Digest getHashById(int hashId) { Digest ret = null;/*from ww w . j av a2s . com*/ switch (hashId) { case DerEncoder.NDX_SHA1: ret = new SHA1Digest(); break; case DerEncoder.NDX_SHA224: ret = new SHA224Digest(); break; case DerEncoder.NDX_SHA256: ret = new SHA256Digest(); break; case DerEncoder.NDX_SHA384: ret = new SHA384Digest(); break; case DerEncoder.NDX_SHA512: ret = new SHA512Digest(); break; default: break; } return ret; }
From source file:cologne.eck.peafactory.gui.Menu.java
License:Open Source License
@Override public void actionPerformed(ActionEvent ape) { //JComponent source = (JComponent) ape.getSource(); String command = ape.getActionCommand(); //Menu//from w ww.j a va 2 s . com if (command.equals("newProject")) { ProjectSelection proj = new ProjectSelection(); Point p = MainView.getFrameLocation(); proj.setLocation((int) p.getX() + 100, (int) p.getY() + 60); proj.setVisible(true); } else if (command.equals("randomPassword")) { PasswordGeneratorDialog pg = new PasswordGeneratorDialog(PeaFactory.getFrame()); pg.setVisible(true); } else if (command.equals("keyboard")) { int input = JOptionPane.showConfirmDialog(PeaFactory.getFrame(), languageBundle.getString("add_keyboard"), " ", JOptionPane.YES_NO_OPTION); if (input == 0) { FileModifier.setSetKeyboard(true); } else { FileModifier.setSetKeyboard(false); } } else if (command.equals("psw_generator")) { int input = JOptionPane.showConfirmDialog(PeaFactory.getFrame(), languageBundle.getString("add_psw_generator"), " ", JOptionPane.YES_NO_OPTION); if (input == 0) { FileModifier.setPswGenerator(true); } else { FileModifier.setPswGenerator(false); } } else if (command.equals("quit")) { System.exit(0); } else if (command.equals("generalPeaSettings")) { @SuppressWarnings("unused") GeneralPeaSettings imageSetting = new GeneralPeaSettings(); } else if (command.equals("setThoughtless")) { securityLevel = 1; setSecurityLevel(1); } else if (command.equals("setLow")) { securityLevel = 2; setSecurityLevel(2); } else if (command.equals("setStandard")) { securityLevel = 3; setSecurityLevel(3); } else if (command.equals("setHigh")) { securityLevel = 4; setSecurityLevel(4); } else if (command.equals("setParanoid")) { securityLevel = 5; setSecurityLevel(5); } else if (command.equals("setBcrypt")) { setSecurityLevel(securityLevel); KeyDerivation.setKdf(new BcryptKDF()); } else if (command.equals("setScrypt")) { setSecurityLevel(securityLevel); KeyDerivation.setKdf(new ScryptKDF()); } else if (command.equals("setDragonfly")) { setSecurityLevel(securityLevel); CatenaKDF.setVersionID("Dragonfly-Full"); KeyDerivation.setKdf(new CatenaKDF()); } else if (command.equals("setButterfly")) { setSecurityLevel(securityLevel); CatenaKDF.setVersionID("Butterfly-Full"); KeyDerivation.setKdf(new CatenaKDF()); } else if (command.equals("setPomelo")) { setSecurityLevel(securityLevel); KeyDerivation.setKdf(new PomeloKDF()); } else if (command.equals("setBcryptParameters")) { @SuppressWarnings("unused") BcryptSetting bcryptSetting = new BcryptSetting(); } else if (command.equals("setPomeloParameters")) { @SuppressWarnings("unused") PomeloSetting pomeloSetting = new PomeloSetting(); } else if (command.equals("setScryptParameters")) { @SuppressWarnings("unused") ScryptSetting scryptSetting = new ScryptSetting(); } else if (command.equals("setCatenaParameters")) { @SuppressWarnings("unused") CatenaSetting catenaSetting = new CatenaSetting(); } else if (command.equals("setImageParameters")) { @SuppressWarnings("unused") ImageSetting imageSetting = new ImageSetting(); } else if (command.equals("setShacal2")) { CipherStuff.setCipherAlgo(new Shacal2Engine()); } else if (command.equals("setThreefish256")) { CipherStuff.setCipherAlgo(new ThreefishEngine(256)); } else if (command.equals("setThreefish512")) { CipherStuff.setCipherAlgo(new ThreefishEngine(512)); } else if (command.equals("setThreefish1024")) { CipherStuff.setCipherAlgo(new ThreefishEngine(1024)); } else if (command.equals("setTwofish")) { CipherStuff.setCipherAlgo(new TwofishEngine()); } else if (command.equals("setSerpent")) { CipherStuff.setCipherAlgo(new SerpentEngine()); } else if (command.equals("setAES")) { CipherStuff.setCipherAlgo(new AESEngine()); } else if (command.equals("setAESFast")) { CipherStuff.setCipherAlgo(new AESFastEngine()); // hash function: } else if (command.equals("setWhirlpool")) { HashStuff.setHashAlgo(new WhirlpoolDigest()); } else if (command.equals("setKeccak")) { HashStuff.setHashAlgo(new SHA3Digest()); } else if (command.equals("setSha512")) { HashStuff.setHashAlgo(new SHA512Digest()); } else if (command.equals("setSha384")) { HashStuff.setHashAlgo(new SHA384Digest()); } else if (command.equals("setSkein512")) { HashStuff.setHashAlgo(new SkeinDigest(512, 512)); } else if (command.equals("setBlake512")) { HashStuff.setHashAlgo(new Blake2bDigest()); // } else if (command.equals("setRipemd256")) { // HashStuff.setHashAlgo( new RIPEMD256Digest() ); } else if (command.equals("setRipemd320")) { HashStuff.setHashAlgo(new RIPEMD320Digest()); } else if (command.equals("setDE")) { PeaFactory.setI18n("de"); } else if (command.equals("setEN")) { PeaFactory.setI18n("en"); } else if (command.equals("notes")) { @SuppressWarnings("unused") InfoDialog info = new InfoDialog(languageBundle.getString("notes_description"), null, "notes"); } else if (command.equals("editor")) { @SuppressWarnings("unused") InfoDialog info = new InfoDialog(languageBundle.getString("editor_description"), null, "editor"); } else if (command.equals("image")) { @SuppressWarnings("unused") InfoDialog info = new InfoDialog(languageBundle.getString("image_description"), null, "image"); } else if (command.equals("keyboard_info")) { @SuppressWarnings("unused") InfoDialog info = new InfoDialog("Onscreen Keyboard", null, "keyboard"); } else if (command.equals("file")) { @SuppressWarnings("unused") InfoDialog info = new InfoDialog(languageBundle.getString("file_description"), null, "file"); } else if (command.equals("problemHelp")) { JOptionPane pane = new JOptionPane(languageBundle.getString("problem_help_dialog"), JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_OPTION, null, null);//new ImageIcon(PswDialogView.getImage()), null); pane.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 12)); //pane.setIconImage(PswDialogView.getImage()); pane.setVisible(true); //pane.showMessageDialog(null, languageBundle.getString("problem_help_dialog"), null, JOptionPane.PLAIN_MESSAGE); } else if (command.equals("howToUse")) { JOptionPane.showMessageDialog(PeaFactory.getFrame(), languageBundle.getString("how_to_use_dialog"), null, JOptionPane.PLAIN_MESSAGE); } else if (command.equals("aboutLicense")) { JOptionPane.showMessageDialog(PeaFactory.getFrame(), languageBundle.getString("about_license_dialog"), null, JOptionPane.PLAIN_MESSAGE); } }
From source file:com.amazonaws.encryptionsdk.CryptoAlgorithm.java
License:Open Source License
public SecretKey getEncryptionKeyFromDataKey(final SecretKey dataKey, final CiphertextHeaders headers) throws InvalidKeyException { if (!dataKey.getAlgorithm().equalsIgnoreCase(getDataKeyAlgo())) { throw new InvalidKeyException("DataKey of incorrect algorithm. Expected " + getDataKeyAlgo() + " but was " + dataKey.getAlgorithm()); }//ww w.j av a 2 s. c om final Digest dgst; switch (this) { case ALG_AES_128_GCM_IV12_TAG16_NO_KDF: case ALG_AES_192_GCM_IV12_TAG16_NO_KDF: case ALG_AES_256_GCM_IV12_TAG16_NO_KDF: return dataKey; case ALG_AES_128_GCM_IV12_TAG16_HKDF_SHA256: case ALG_AES_192_GCM_IV12_TAG16_HKDF_SHA256: case ALG_AES_256_GCM_IV12_TAG16_HKDF_SHA256: case ALG_AES_128_GCM_IV12_TAG16_HKDF_SHA256_ECDSA_P256: dgst = new SHA256Digest(); break; case ALG_AES_192_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384: case ALG_AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384: dgst = new SHA384Digest(); break; default: throw new UnsupportedOperationException("Support for " + this + " not yet built."); } if (!dataKey.getFormat().equalsIgnoreCase("RAW")) { throw new InvalidKeyException( "Currently only RAW format keys are supported for HKDF algorithms. Actual format was " + dataKey.getFormat()); } final byte[] messageId = headers.getMessageId(); final ByteBuffer info = ByteBuffer.allocate(messageId.length + 2); info.order(ByteOrder.BIG_ENDIAN); info.putShort(getValue()); info.put(messageId); final byte[] rawDataKey = dataKey.getEncoded(); if (rawDataKey.length != getDataKeyLength()) { throw new InvalidKeyException("DataKey of incorrect length. Expected " + getDataKeyLength() + " but was " + rawDataKey.length); } final byte[] rawEncKey = new byte[getKeyLength()]; final HKDFBytesGenerator hkdf = new HKDFBytesGenerator(dgst); hkdf.init(new HKDFParameters(rawDataKey, null, info.array())); hkdf.generateBytes(rawEncKey, 0, getKeyLength()); return new SecretKeySpec(rawEncKey, getKeyAlgo()); }
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 *///from w w w .j av a 2 s .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.licel.jcardsim.crypto.MessageDigestImpl.java
License:Apache License
public MessageDigestImpl(byte algorithm) { this.algorithm = algorithm; blockSize = 64;//from w w w . ja va2 s . 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.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); }// ww w . jav a 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:COSE.MacCommon.java
private byte[] HMAC(CBORObject alg, byte[] rgbKey) throws CoseException { Digest digest;/*from www. j a va2s . c om*/ int cbitKey; int cbResult; switch (alg.AsInt32()) { case 4: // HMAC_SHA_256_64 cbitKey = 256; cbResult = 64 / 8; digest = new SHA256Digest(); break; case 5: // HMAC_SHA_256 cbitKey = 256; cbResult = 256 / 8; digest = new SHA256Digest(); break; case 6: // HMAC_SHA_384 cbitKey = 384; cbResult = 384 / 8; digest = new SHA384Digest(); break; case 7: // HMAC_SHA_512 cbitKey = 512; cbResult = 512 / 8; digest = new SHA512Digest(); break; default: throw new CoseException("Internal Error"); } if (rgbKey.length != cbitKey / 8) throw new CoseException("Key is incorrect size"); HMac hmac = new HMac(digest); KeyParameter key = new KeyParameter(rgbKey); byte[] toDigest = BuildContentBytes(); byte[] resBuf = new byte[hmac.getMacSize()]; hmac.init(key); hmac.update(toDigest, 0, toDigest.length); hmac.doFinal(resBuf, 0); byte[] returnVal = new byte[cbResult]; System.arraycopy(resBuf, 0, returnVal, 0, cbResult); return returnVal; }
From source file:COSE.SignCommon.java
byte[] computeSignature(byte[] rgbToBeSigned, CipherParameters key) throws CoseException { AlgorithmID alg = AlgorithmID.FromCBOR(findAttribute(HeaderKeys.Algorithm)); Digest digest;/* ww w. java2s. c om*/ CBORObject cn; switch (alg) { case ECDSA_256: digest = new SHA256Digest(); break; case ECDSA_384: digest = new SHA384Digest(); break; case ECDSA_512: digest = new SHA512Digest(); break; default: throw new CoseException("Unsupported Algorithm Specified"); } switch (alg) { case ECDSA_256: case ECDSA_384: case ECDSA_512: { digest.update(rgbToBeSigned, 0, rgbToBeSigned.length); byte[] rgbDigest = new byte[digest.getDigestSize()]; digest.doFinal(rgbDigest, 0); ECDSASigner ecdsa = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest())); ecdsa.init(true, key); BigInteger[] sig = ecdsa.generateSignature(rgbDigest); int cb = (((ECPrivateKeyParameters) key).getParameters().getCurve().getFieldSize() + 7) / 8; byte[] r = sig[0].toByteArray(); byte[] s = sig[1].toByteArray(); byte[] sigs = new byte[cb * 2]; int cbR = min(cb, r.length); System.arraycopy(r, r.length - cbR, sigs, cb - cbR, cbR); cbR = min(cb, s.length); System.arraycopy(s, s.length - cbR, sigs, cb + cb - cbR, cbR); return sigs; } default: throw new CoseException("Inernal error"); } }
From source file:COSE.SignCommon.java
byte[] computeSignature(byte[] rgbToBeSigned, OneKey cnKey) throws CoseException { AlgorithmID alg = AlgorithmID.FromCBOR(findAttribute(HeaderKeys.Algorithm)); Digest digest;//from ww w . j av a 2 s. co m CBORObject cn; switch (alg) { case ECDSA_256: digest = new SHA256Digest(); break; case ECDSA_384: digest = new SHA384Digest(); break; case ECDSA_512: digest = new SHA512Digest(); break; default: throw new CoseException("Unsupported Algorithm Specified"); } switch (alg) { case ECDSA_256: case ECDSA_384: case ECDSA_512: { digest.update(rgbToBeSigned, 0, rgbToBeSigned.length); byte[] rgbDigest = new byte[digest.getDigestSize()]; digest.doFinal(rgbDigest, 0); cn = cnKey.get(KeyKeys.KeyType); if ((cn == null) || (cn != KeyKeys.KeyType_EC2)) throw new CoseException("Must use key with key type EC2"); cn = cnKey.get(KeyKeys.EC2_D); if (cn == null) throw new CoseException("Private key required to sign"); X9ECParameters p = cnKey.GetCurve(); ECDomainParameters parameters = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH()); ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(new BigInteger(1, cn.GetByteString()), parameters); ECDSASigner ecdsa = new ECDSASigner(); ecdsa.init(true, privKey); BigInteger[] sig = ecdsa.generateSignature(rgbDigest); int cb = (p.getCurve().getFieldSize() + 7) / 8; byte[] r = sig[0].toByteArray(); byte[] s = sig[1].toByteArray(); byte[] sigs = new byte[cb * 2]; int cbR = min(cb, r.length); System.arraycopy(r, r.length - cbR, sigs, cb - cbR, cbR); cbR = min(cb, s.length); System.arraycopy(s, s.length - cbR, sigs, cb + cb - cbR, cbR); return sigs; } default: throw new CoseException("Inernal error"); } }
From source file:COSE.SignCommon.java
boolean validateSignature(byte[] rgbToBeSigned, byte[] rgbSignature, CipherParameters key) throws CoseException { AlgorithmID alg = AlgorithmID.FromCBOR(findAttribute(HeaderKeys.Algorithm)); Digest digest;/*from w w w . j a va 2s . c om*/ switch (alg) { case ECDSA_256: digest = new SHA256Digest(); break; case ECDSA_384: digest = new SHA384Digest(); break; case ECDSA_512: digest = new SHA512Digest(); break; default: throw new CoseException("Unsupported algorithm specified"); } switch (alg) { case ECDSA_256: case ECDSA_384: case ECDSA_512: { byte[] rgbR = new byte[rgbSignature.length / 2]; byte[] rgbS = new byte[rgbSignature.length / 2]; System.arraycopy(rgbSignature, 0, rgbR, 0, rgbR.length); System.arraycopy(rgbSignature, rgbR.length, rgbS, 0, rgbR.length); digest.update(rgbToBeSigned, 0, rgbToBeSigned.length); byte[] rgbDigest = new byte[digest.getDigestSize()]; digest.doFinal(rgbDigest, 0); ECDSASigner ecdsa = new ECDSASigner(); ecdsa.init(false, key); return ecdsa.verifySignature(rgbDigest, new BigInteger(1, rgbR), new BigInteger(1, rgbS)); } default: throw new CoseException("Internal error"); } }