List of usage examples for java.security GeneralSecurityException getMessage
public String getMessage()
From source file:Main.java
private static byte[] getSHA1Digest(String data) throws IOException { byte[] bytes = null; try {/*from w ww .j a v a 2s . c o m*/ MessageDigest md = MessageDigest.getInstance("SHA-1"); bytes = md.digest(data.getBytes("UTF-8")); } catch (GeneralSecurityException gse) { throw new IOException(gse.getMessage()); } return bytes; }
From source file:com.diaw.lib.tool.FakeSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {//w w w .j av a 2s . co m final SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new NaiveTrustManager() }, null); return context; } catch (GeneralSecurityException e) { throw new IOException(e.getMessage()); } }
From source file:com.pfw.popsicle.common.Digests.java
private static byte[] digest(InputStream input, String algorithm) throws IOException { try {//from www . ja v a 2 s .c o m MessageDigest messageDigest = MessageDigest.getInstance(algorithm); int bufferLength = 8 * 1024; byte[] buffer = new byte[bufferLength]; int read = input.read(buffer, 0, bufferLength); while (read > -1) { messageDigest.update(buffer, 0, read); read = input.read(buffer, 0, bufferLength); } return messageDigest.digest(); } catch (GeneralSecurityException e) { throw new IOException(e.getMessage()); } }
From source file:com.adeptj.modules.security.jwt.internal.JwtKeys.java
static PublicKey createVerificationKey(SignatureAlgorithm signatureAlgo, String publicKey) { LOGGER.info("Creating RSA verification key!!"); Assert.isTrue(StringUtils.startsWith(publicKey, PUB_KEY_HEADER), INVALID_PUBLIC_KEY_MSG); try {/*w w w. j av a2s . c om*/ KeyFactory keyFactory = KeyFactory.getInstance(signatureAlgo.getFamilyName()); byte[] publicKeyData = Base64.getDecoder().decode(publicKey.replace(PUB_KEY_HEADER, EMPTY) .replace(PUB_KEY_FOOTER, EMPTY).replaceAll(REGEX_SPACE, EMPTY).trim().getBytes(UTF_8)); LOGGER.info("Creating X509EncodedKeySpec from public key !!"); return keyFactory.generatePublic(new X509EncodedKeySpec(publicKeyData)); } catch (GeneralSecurityException ex) { LOGGER.error(ex.getMessage(), ex); throw new KeyInitializationException(ex.getMessage(), ex); } }
From source file:org.entrystore.repository.security.Password.java
private static String hash(String password, byte[] salt) { if (password == null || password.length() == 0) { throw new IllegalArgumentException("Empty passwords are not supported"); }/*from w ww . j a v a2s. c om*/ try { long before = new Date().getTime(); SecretKey key = secretKeyFactory .generateSecret(new PBEKeySpec(password.toCharArray(), salt, iterations, desiredKeyLen)); log.info("Password hashing took " + (new Date().getTime() - before) + " ms"); return Base64.encodeBase64String(key.getEncoded()); } catch (GeneralSecurityException gse) { log.error(gse.getMessage()); } return null; }
From source file:com.axelor.apps.account.ebics.certificate.KeyUtil.java
/** * Returns the digest value of a given public key. * //from w ww . j av a 2 s .com * * <p>In Version H003? of the EBICS protocol the ES of the financial: * * <p>The SHA-256 hash values of the financial institution's public keys for X002 and E002 are * composed by concatenating the exponent with a blank character and the modulus in hexadecimal * representation (using lower case letters) without leading zero (as to the hexadecimal * representation). The resulting string has to be converted into a byte array based on US ASCII * code. * * @param publicKey the public key * @return the digest value * @throws EbicsException */ public static byte[] getKeyDigest(RSAPublicKey publicKey) throws AxelorException { String modulus; String exponent; String hash; byte[] digest; exponent = Hex.encodeHexString(publicKey.getPublicExponent().toByteArray()); modulus = Hex.encodeHexString(removeFirstByte(publicKey.getModulus().toByteArray())); hash = exponent + " " + modulus; if (hash.charAt(0) == '0') { hash = hash.substring(1); } try { digest = MessageDigest.getInstance("SHA-256", "BC").digest(hash.getBytes("US-ASCII")); } catch (GeneralSecurityException e) { throw new AxelorException(e.getMessage(), IException.CONFIGURATION_ERROR); } catch (UnsupportedEncodingException e) { throw new AxelorException(e.getMessage(), IException.CONFIGURATION_ERROR); } return new String(Hex.encodeHex(digest, false)).getBytes(); }
From source file:org.kopi.ebics.certificate.KeyUtil.java
/** * Returns the digest value of a given public key. * // w ww .j av a 2 s .c om * * <p>In Version H003? of the EBICS protocol the ES of the financial: * * <p>The SHA-256 hash values of the financial institution's public keys for X002 and E002 are * composed by concatenating the exponent with a blank character and the modulus in hexadecimal * representation (using lower case letters) without leading zero (as to the hexadecimal * representation). The resulting string has to be converted into a byte array based on US ASCII * code. * * @param publicKey the public key * @return the digest value * @throws EbicsException */ public static byte[] getKeyDigest(RSAPublicKey publicKey) throws EbicsException { String modulus; String exponent; String hash; byte[] digest; exponent = Hex.encodeHexString(publicKey.getPublicExponent().toByteArray()); modulus = Hex.encodeHexString(removeFirstByte(publicKey.getModulus().toByteArray())); hash = exponent + " " + modulus; if (hash.charAt(0) == '0') { hash = hash.substring(1); } try { digest = MessageDigest.getInstance("SHA-256", "BC").digest(hash.getBytes("US-ASCII")); } catch (GeneralSecurityException e) { throw new EbicsException(e.getMessage()); } catch (UnsupportedEncodingException e) { throw new EbicsException(e.getMessage()); } return new String(Hex.encodeHex(digest, false)).getBytes(); }
From source file:com.ntsync.android.sync.client.MySSLSocketFactory.java
private static SSLContext createEasySSLContext() throws IOException { try {//w ww . ja v a2 s.c o m SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new MyX509TrustManager() }, null); return context; } catch (GeneralSecurityException e) { Log.e(TAG, "Init SSLContext failed.", e); throw new IOException(e.getMessage()); } }
From source file:pepperim.util.IMCrypt.java
/** * RSA encryption. You can use a PrivateKey here, if you need a custom signing algorithm (otherwise you can use {@link #RSA_Sign(String,PrivateKey)}) * @param data Data to be encrypted (should not be more than some dozen bytes!) * @param key Encryption key (PublicKey or PrivateKey) * @return Base64-encoded encrypted data *//* w ww.j a v a 2 s .co m*/ public static String RSA_Enc(String data, Key key) { try { Cipher c = Cipher.getInstance("RSA"); c.init(Cipher.ENCRYPT_MODE, key); return B64_Enc(c.doFinal(data.getBytes())); } catch (GeneralSecurityException e) { Main.log(e.getMessage()); return ""; } }
From source file:pepperim.util.IMCrypt.java
/** * @param data Base64-encoded encrypted data * @param key Decryption key (normally PrivateKey, but can also be PublicKey if you do custom signing) * @return decrypted data/*ww w .ja va2 s . c o m*/ */ public static String RSA_Dec(String data, Key key) { try { Cipher c = Cipher.getInstance("RSA"); c.init(Cipher.DECRYPT_MODE, key); return new String(c.doFinal(B64_Dec(data))); } catch (GeneralSecurityException e) { Main.log(e.getMessage()); return ""; } }