All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.manydesigns.crypto.CryptoUtils Maven / Gradle / Ivy

package com.manydesigns.crypto;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.security.MessageDigest;

class CryptoUtils {
     private static final Logger logger = LoggerFactory.getLogger(CryptoUtils.class);
     private static final int PASS_MIN_LEN = 8;

    protected static String getKey(String filename) throws IOException {
        // Read key from file
        String strKey = "";
        try (BufferedReader br = new BufferedReader(new FileReader(filename))) {
            String line;
            while ((line = br.readLine()) != null) {
                strKey += line + "\n";
            }
        } catch (IOException e) {
            logger.error("getKey from "+filename+": "+e.getMessage());
            throw e;
        }
        return strKey;
    }


     static void checkPassphrase(String pass) throws InvalidPassphraseException {
        if(  pass==null ){
            throw new InvalidPassphraseException("Passphrase is null");
        }
        if(pass.equals("")){
            throw new InvalidPassphraseException("Passphrase is empty");
        }
        if( pass.length()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy