Example usage for java.security NoSuchAlgorithmException printStackTrace

List of usage examples for java.security NoSuchAlgorithmException printStackTrace

Introduction

In this page you can find the example usage for java.security NoSuchAlgorithmException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:it.staiger.jmeter.services.FileContentServer.java

/**
 * Get String of SHA256 hash for provided byte array,
 * @param content byte array/*from  ww w  . jav a  2  s .c o  m*/
 * @return String SHA256 hash
 */
private String getSHA256(byte[] content) {
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-256");
        return new String(Hex.encodeHex(md.digest(content)));
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.persistent.cloudninja.scheduler.TenantCreationTask.java

/**
 * This method returns the SHA-1 encoded HexPassword
 * //from   w  w  w .  j a  v a2 s .  c om
 * @param password
 *            the plain text password
 * @return hexpassword The SHA-1 encoded Hex password.
 */
private String getSHA1hexPassword(String password) {

    String hexPassword = "";

    if (password != null && password.length() > 0) {

        try {
            MessageDigest sha1Digest = MessageDigest.getInstance("SHA-1");
            sha1Digest.update(password.getBytes());
            hexPassword = new String(Hex.encodeHex(sha1Digest.digest())).toUpperCase();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
    return hexPassword;
}

From source file:algorithm.AesEncryption.java

private void setKey(String function) {

    MessageDigest sha = null;//from www . ja  va  2 s.  c  om
    try {
        //File f = new File("Aes_key");
        key = new byte[16];
        //   KeyGenerator kgen = KeyGenerator.getInstance("AES");

        //TODO : SET 128/196/256 keysize
        //generise kljuc od 128
        //         kgen.init(128);
        //NE KORISTI SE!!!
        //      secretKey = kgen.generateKey();
        //TODO : Set md5/SHA / SHA-1/ SHA-256
        //   sha = MessageDigest.getInstance("SHA-256");
        sha = MessageDigest.getInstance(function);
        key = sha.digest(key);

        // use only first 128 bit
        key = Arrays.copyOf(key, 16);

        secretKeySpec = new SecretKeySpec(key, "AES");

        //  new FileOutputStream(f).write(key);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
}

From source file:org.jhub1.agent.randoms.Randoms.java

public String sha1(String str) {
    MessageDigest cript = null;//from  w  ww .  j a  v a  2s .  c  o  m
    try {
        cript = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    cript.reset();
    try {
        cript.update(str.getBytes("utf8"));
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return new String(Hex.encodeHex(cript.digest()));
}

From source file:jp.co.yahoo.yconnect.core.oidc.JWTVerification.java

/**
 * HMAC-SHA256????????????/*  w w  w.  j  a  v  a 2  s . co m*/
 * 
 * @return ?????
 */
private String generateSignature() {
    // mac???
    Mac sha256_HMAC = null;
    try {
        sha256_HMAC = Mac.getInstance("HmacSHA256");
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }

    // secret_key??
    SecretKeySpec secret_key = null;
    try {
        secret_key = new SecretKeySpec(this.clientSecret.getBytes("UTF-8"), "HmacSHA256");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    // mac??
    try {
        sha256_HMAC.init(secret_key);
    } catch (InvalidKeyException e) {
        e.printStackTrace();
    }

    String[] idTokenArray = this.idTokenString.split("\\.");
    this.dataPart = idTokenArray[0] + "." + idTokenArray[1];

    String hash = null;
    try {
        hash = Base64.encodeBase64String(sha256_HMAC.doFinal(this.dataPart.getBytes("UTF-8")));
    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    // URLSafe?Base64??
    hash = hash.replace("=", "");
    hash = hash.replace("+", "-");
    hash = hash.replace("/", "_");

    return hash;
}

From source file:corner.encrypt.services.impl.DESedeEncryptServiceImpl.java

/**
 * @see corner.encrypt.services.EncryptService#encrypt(byte[], byte[])
 *///from   w ww . j a va2s .  co  m
@Override
public byte[] encrypt(byte[] src, byte[] key) {
    try {
        SecretKey deskey = new SecretKeySpec(key, Algorithm);
        Cipher c1 = Cipher.getInstance(Algorithm);
        c1.init(Cipher.ENCRYPT_MODE, deskey);
        return c1.doFinal(src);
    } catch (java.security.NoSuchAlgorithmException e1) {
        e1.printStackTrace();
    } catch (javax.crypto.NoSuchPaddingException e2) {
        e2.printStackTrace();
    } catch (java.lang.Exception e3) {
        e3.printStackTrace();
    }
    return null;
}

From source file:corner.encrypt.services.impl.DESedeEncryptServiceImpl.java

/**
 * @see corner.encrypt.services.EncryptService#decrypt(byte[], byte[])
 *///from  ww  w.jav  a 2s.  com
@Override
public byte[] decrypt(byte[] src, byte[] keybyte) {
    try {
        SecretKey deskey = new SecretKeySpec(keybyte, Algorithm);
        Cipher c1 = Cipher.getInstance(Algorithm);
        c1.init(Cipher.DECRYPT_MODE, deskey);
        return c1.doFinal(src);
    } catch (java.security.NoSuchAlgorithmException e1) {
        e1.printStackTrace();
    } catch (javax.crypto.NoSuchPaddingException e2) {
        e2.printStackTrace();
    } catch (java.lang.Exception e3) {
        e3.printStackTrace();
    }
    return null;
}

From source file:org.hil.systemadministrator.systemusermanagement.service.impl.SystemUserManagerImpl.java

public SystemAccount savePassword(SystemAccount sa, String newpassword) {
    String md5Password = "";
    try {/*from w  w  w  .  ja  v  a2 s . c  o  m*/
        md5Password = MD5.MD5(newpassword.toLowerCase());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    sa.setPassword(md5Password);
    sa = systemAccountDao.save(sa);
    return sa;
}

From source file:de.iai.ilcd.model.common.XmlFile.java

public byte[] getContentHash() {
    MessageDigest md;/*  w ww.j  a va2s.  c  o  m*/
    try {
        md = MessageDigest.getInstance("MD5");
        return md.digest(this.compressedContent);
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    }
    return new byte[0];
}

From source file:fr.tse.fi2.hpp.labs.queries.impl.lab5.BloomFilterQuery.java

public boolean contain(String plaque, float loD, float laD, float loA, float laA) {
    String str = plaque + laA + loA + laD + loD;
    String[] str2hash = new String[k];

    MessageDigest md = null;//from   w  w  w .j a  v a  2s.  co  m
    try {
        md = MessageDigest.getInstance("SHA-256");
    } catch (NoSuchAlgorithmException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    for (int i = 0; i < 10; i++) {
        str2hash[i] = salt[i] + str;
        try {
            md.update(str2hash.toString().getBytes("UTF-16"));
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        byte[] res = md.digest();
        BigInteger indiceB = new BigInteger(res);
        int indice = indiceB.intValue();

        if (indice < 0)
            indice = -indice;
        indice = indice % 14378;
        if (!bloomFilter.get(indice))
            return false;
    }
    return true;
}