List of usage examples for org.bouncycastle.crypto.digests SHA3Digest SHA3Digest
public SHA3Digest()
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/*ww w . j a va 2 s. co m*/ 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:org.hyperledger.fabric.sdk.helper.SDKUtil.java
License:Open Source License
/** * Generate parameter hash for the given chain code path,func and args * @param path Chain code path/*from www .ja v a 2 s. co m*/ * @param func Chain code function name * @param args List of arguments * @return hash of path, func and args */ public static String generateParameterHash(String path, String func, List<String> args) { logger.debug(String.format("GenerateParameterHash : path=%s, func=%s, args=%s", path, func, args)); // Append the arguments StringBuilder param = new StringBuilder(path); param.append(func); args.forEach(param::append); // Compute the hash String strHash = Hex.toHexString(hash(param.toString().getBytes(), new SHA3Digest())); return strHash; }
From source file:org.hyperledger.fabric.sdk.helper.SDKUtil.java
License:Open Source License
/** * Generate hash of a chain code directory * @param rootDir Root directory//from w w w . j ava 2s .co m * @param chaincodeDir Chain code directory * @param hash Previous hash (if any) * @return hash of the directory * @throws IOException */ public static String generateDirectoryHash(String rootDir, String chaincodeDir, String hash) throws IOException { // Generate the project directory Path projectPath = null; if (rootDir == null) { projectPath = Paths.get(chaincodeDir); } else { projectPath = Paths.get(rootDir, chaincodeDir); } File dir = projectPath.toFile(); if (!dir.exists() || !dir.isDirectory()) { throw new IOException(String.format("The chaincode path \"%s\" is invalid", projectPath)); } StringBuilder hashBuilder = new StringBuilder(hash); Files.walk(projectPath).sorted(Comparator.naturalOrder()).filter(Files::isRegularFile).map(Path::toFile) .forEach(file -> { try { byte[] buf = readFile(file); byte[] toHash = Arrays.concatenate(buf, hashBuilder.toString().getBytes()); hashBuilder.setLength(0); hashBuilder.append(Hex.toHexString(hash(toHash, new SHA3Digest()))); } catch (IOException ex) { throw new RuntimeException( String.format("Error while reading file %s", file.getAbsolutePath()), ex); } }); // If original hash and final hash are the same, it indicates that no new contents were found if (hashBuilder.toString().equals(hash)) { throw new IOException(String.format("The chaincode directory \"%s\" has no files", projectPath)); } return hashBuilder.toString(); }
From source file:org.hyperledger.fabric.sdk.helper.Utils.java
License:Open Source License
/** * Generate parameter hash for the given chaincode path,func and args * * @param path Chaincode path//from w w w . j a v a 2 s. com * @param func Chaincode function name * @param args List of arguments * @return hash of path, func and args */ public static String generateParameterHash(String path, String func, List<String> args) { logger.debug(String.format("GenerateParameterHash : path=%s, func=%s, args=%s", path, func, args)); // Append the arguments StringBuilder param = new StringBuilder(path); param.append(func); args.forEach(param::append); // Compute the hash return Hex.toHexString(hash(param.toString().getBytes(UTF_8), new SHA3Digest())); }
From source file:org.hyperledger.fabric.sdk.helper.Utils.java
License:Open Source License
/** * Generate hash of a chaincode directory * * @param rootDir Root directory//from w ww . j a v a 2s. c o m * @param chaincodeDir Channel code directory * @param hash Previous hash (if any) * @return hash of the directory * @throws IOException */ public static String generateDirectoryHash(String rootDir, String chaincodeDir, String hash) throws IOException { // Generate the project directory Path projectPath = null; if (rootDir == null) { projectPath = Paths.get(chaincodeDir); } else { projectPath = Paths.get(rootDir, chaincodeDir); } File dir = projectPath.toFile(); if (!dir.exists() || !dir.isDirectory()) { throw new IOException(String.format("The chaincode path \"%s\" is invalid", projectPath)); } StringBuilder hashBuilder = new StringBuilder(hash); Files.walk(projectPath).sorted(Comparator.naturalOrder()).filter(Files::isRegularFile).map(Path::toFile) .forEach(file -> { try { byte[] buf = readFile(file); byte[] toHash = Arrays.concatenate(buf, hashBuilder.toString().getBytes(UTF_8)); hashBuilder.setLength(0); hashBuilder.append(Hex.toHexString(hash(toHash, new SHA3Digest()))); } catch (IOException ex) { throw new RuntimeException( String.format("Error while reading file %s", file.getAbsolutePath()), ex); } }); // If original hash and final hash are the same, it indicates that no new contents were found if (hashBuilder.toString().equals(hash)) { throw new IOException(String.format("The chaincode directory \"%s\" has no files", projectPath)); } return hashBuilder.toString(); }
From source file:org.hyperledger.fabric.sdk.helper.UtilsTest.java
License:Open Source License
@Test public void testGenerateParameterHash() { List<String> args = new ArrayList<>(); args.add("a"); args.add("b"); String hash = Utils.generateParameterHash("mypath", "myfunc", args); Assert.assertEquals(Hex.toHexString(Utils.hash("mypathmyfuncab".getBytes(UTF_8), new SHA3Digest())), hash); }
From source file:org.hyperledger.fabric.sdk.helper.UtilsTest.java
License:Open Source License
@Test public void testHash() { byte[] input = "TheQuickBrownFox".getBytes(UTF_8); String expectedHash = "feb69c5c360a15802de6af23a3f5622da9d96aff2be78c8f188cce57a3549db6"; byte[] hash = Utils.hash(input, new SHA3Digest()); Assert.assertEquals(expectedHash, Hex.toHexString(hash)); }
From source file:org.hyperledger.fabric.sdk.SDKUtilTest.java
License:Open Source License
@Test public void testGenerateParameterHash() { List<String> args = new ArrayList<String>(); args.add("a"); args.add("b"); String hash = SDKUtil.generateParameterHash("mypath", "myfunc", args); Assert.assertEquals(Hex.toHexString(SDKUtil.hash("mypathmyfuncab".getBytes(), new SHA3Digest())), hash); }
From source file:org.hyperledger.fabric.sdk.security.CryptoPrimitives.java
License:Open Source License
private Digest getHashDigest() { if (this.hashAlgorithm.equalsIgnoreCase("SHA3")) { return new SHA3Digest(); } else if (this.hashAlgorithm.equalsIgnoreCase("SHA2")) { return new SHA256Digest(); }//from w w w. j a va 2 s .c o m return new SHA256Digest(); // default Digest? }