Java Code Examples for java.security.NoSuchAlgorithmException#getLocalizedMessage()

The following examples show how to use java.security.NoSuchAlgorithmException#getLocalizedMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SSHAPasswordEncryptor.java    From codenvy with Eclipse Public License 1.0 6 votes vote down vote up
public byte[] encrypt(byte[] password) {
  byte[] salt = new byte[6];
  SECURE_RANDOM.nextBytes(salt);
  try {
    byte[] buff = new byte[password.length + salt.length];
    System.arraycopy(password, 0, buff, 0, password.length);
    System.arraycopy(salt, 0, buff, password.length, salt.length);

    byte[] res = new byte[20 + salt.length];
    MessageDigest md = MessageDigest.getInstance("SHA");
    md.reset();
    System.arraycopy(md.digest(buff), 0, res, 0, 20);
    System.arraycopy(salt, 0, res, 20, salt.length);

    return (SSHA_PREFIX + Base64.getEncoder().encodeToString(res)).getBytes();
  } catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e.getLocalizedMessage());
  }
}
 
Example 2
Source File: SSHAPasswordEncryptor.java    From codenvy with Eclipse Public License 1.0 6 votes vote down vote up
public byte[] encrypt(byte[] password) {
  byte[] salt = new byte[6];
  SECURE_RANDOM.nextBytes(salt);
  try {
    byte[] buff = new byte[password.length + salt.length];
    System.arraycopy(password, 0, buff, 0, password.length);
    System.arraycopy(salt, 0, buff, password.length, salt.length);

    byte[] res = new byte[20 + salt.length];
    MessageDigest md = MessageDigest.getInstance("SHA");
    md.reset();
    System.arraycopy(md.digest(buff), 0, res, 0, 20);
    System.arraycopy(salt, 0, res, 20, salt.length);

    return (SSHA_PREFIX + Base64.getEncoder().encodeToString(res)).getBytes();
  } catch (NoSuchAlgorithmException e) {
    throw new RuntimeException(e.getLocalizedMessage());
  }
}
 
Example 3
Source File: MD5Digester.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public MD5Digester() {
	try {
		md = MessageDigest.getInstance(DIGEST_TYPE);
		md.reset();
	} catch (NoSuchAlgorithmException exc) {
		throw new P4JavaError("Unable to create an MD5 digester for P4Java: "
								+ exc.getLocalizedMessage());
	}
}
 
Example 4
Source File: MD5Digester.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public MD5Digester() throws P4JavaError {
	try {
		messageDigest = MessageDigest.getInstance(DIGEST_TYPE);
		messageDigest.reset();
	} catch (NoSuchAlgorithmException exc) {
		throw new P4JavaError(
				"Unable to create an MD5 digester for P4Java: " + exc.getLocalizedMessage(),
				exc);
	}
}
 
Example 5
Source File: MD5Digester.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public MD5Digester() throws P4JavaError {
	try {
		messageDigest = MessageDigest.getInstance(DIGEST_TYPE);
		messageDigest.reset();
	} catch (NoSuchAlgorithmException exc) {
		throw new P4JavaError(
				"Unable to create an MD5 digester for P4Java: " + exc.getLocalizedMessage(),
				exc);
	}
}
 
Example 6
Source File: MD5Digester.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public MD5Digester() throws P4JavaError {
	try {
		messageDigest = MessageDigest.getInstance(DIGEST_TYPE);
		messageDigest.reset();
	} catch (NoSuchAlgorithmException exc) {
		throw new P4JavaError(
				"Unable to create an MD5 digester for P4Java: " + exc.getLocalizedMessage(),
				exc);
	}
}
 
Example 7
Source File: MD5Digester.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public MD5Digester() throws P4JavaError {
	try {
		messageDigest = MessageDigest.getInstance(DIGEST_TYPE);
		messageDigest.reset();
	} catch (NoSuchAlgorithmException exc) {
		throw new P4JavaError(
				"Unable to create an MD5 digester for P4Java: " + exc.getLocalizedMessage(),
				exc);
	}
}
 
Example 8
Source File: MD5Digester.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
public MD5Digester() {
	try {
		md = MessageDigest.getInstance(DIGEST_TYPE);
		md.reset();
	} catch (NoSuchAlgorithmException exc) {
		throw new P4JavaError("Unable to create an MD5 digester for P4Java: "
								+ exc.getLocalizedMessage());
	}
}