List of usage examples for java.security NoSuchAlgorithmException printStackTrace
public void printStackTrace()
From source file:ch.bfh.evoting.alljoyn.BusHandler.java
/** * Get the public key of the given peer/*from www . j a v a 2 s.co m*/ * @param peerId the peer unique identifier * @return the SHA-256 mod 2^64 of the ASN-1 representation of the public key of the given peer */ public String getPeerPublicKey(String peerId) { if (!identityMap.containsKey(peerId)) { return null; } else { byte[] encodedKey = identityMap.get(peerId).getPublicKey().getEncoded(); MessageDigest digest; try { digest = MessageDigest.getInstance("SHA-256"); byte[] hash = digest.digest(encodedKey); BigInteger hashBI = new BigInteger(hash); return bytesToHex(hashBI.mod(BigInteger.valueOf(2).pow(64)).toByteArray()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return ""; } } }
From source file:org.openintents.safe.CryptoHelper.java
/** * @return//from ww w . java2 s . co m */ private String getTemporaryFileName() throws CryptoHelperException { String randomPart; try { // create a random session name randomPart = generateSalt(); } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); String msg = "Decrypt error: " + e1.getLocalizedMessage(); throw new CryptoHelperException(msg); } return Environment.getExternalStorageDirectory().toString() + "/tmp-" + randomPart; }
From source file:edu.mit.mobile.android.locast.sync.AbsMediaSync.java
/** * Creates a new Media Sync engine./*from ww w .ja v a2 s .c o m*/ */ public AbsMediaSync() { super(); try { mDigest = MessageDigest.getInstance("SHA-1"); } catch (final NoSuchAlgorithmException e) { e.printStackTrace(); mDigest = null; } }
From source file:com.dsna.android.main.MainActivity.java
private KeyStore loadLocalTrustKeystore() { KeyStore localTrustStore;//from w ww .j a v a 2 s .c om try { localTrustStore = KeyStore.getInstance(KeyStore.getDefaultType()); InputStream in = getResources().openRawResource(R.raw.dsnatrustkeystore); try { //System.out.println(FileUtil.readString(in)); localTrustStore.load(in, "kthdsna".toCharArray()); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CertificateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return localTrustStore; } catch (KeyStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
From source file:com.microsoft.rightsmanagement.sampleapp.MsipcTaskFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mApplicationContext = getActivity().getApplicationContext(); // Retain this fragment across configuration changes. setRetainInstance(true);//from www . ja v a2 s.c om updateTaskStatus(new TaskStatus(TaskState.NotStarted, null, false)); mConsentCallback = getConsentCallback(); try { mRmsAuthCallback = App.getInstance().getRmsAuthenticationCallback(getActivity()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); Logger.ie(TAG, e.getMessage()); updateTaskStatus(new TaskStatus(TaskState.Faulted, e.getLocalizedMessage(), true)); } catch (InvalidKeySpecException e) { e.printStackTrace(); Logger.ie(TAG, e.getMessage()); updateTaskStatus(new TaskStatus(TaskState.Faulted, e.getLocalizedMessage(), true)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); Logger.ie(TAG, e.getMessage()); updateTaskStatus(new TaskStatus(TaskState.Faulted, e.getLocalizedMessage(), true)); } }
From source file:org.openintents.safe.CryptoHelper.java
/** * Dencrypt a file previously encrypted with * encryptFileWithSessionKey()./*from w ww.j a v a 2 s . com*/ * <p/> * The original file is not modified * * @param ctx Context of activity in order to store temp file * @param fileUri Uri to either a stream or a file to read from * @return If decryption is successful, returns Uri of a content * provider to read the plaintext file. Upon failure, * return null. * @throws Exception * @author Peli */ public Uri decryptFileWithSessionKeyThroughContentProvider(Context ctx, Uri fileUri) throws CryptoHelperException { if (debug) { Log.d(TAG, "fileUri=" + fileUri.toString()); } ContentResolver contentResolver = ctx.getContentResolver(); String sessionFile = ""; Uri resultUri = null; boolean result = false; try { InputStream is; if (fileUri.getScheme().equals("file")) { is = new java.io.FileInputStream(fileUri.getPath()); if (debug) { Log.d(TAG, "Decrypt: Input from " + fileUri.getPath()); } } else { is = contentResolver.openInputStream(fileUri); if (debug) { Log.d(TAG, "Decrypt: Input from " + fileUri.toString()); } } FileOutputStream os = null; String decryptSession; try { // create a random session name decryptSession = generateSalt(); } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); String msg = "Decrypt error: " + e1.getLocalizedMessage(); throw new CryptoHelperException(msg); } sessionFile = CryptoContentProvider.SESSION_FILE + "." + decryptSession; if (debug) { Log.d(TAG, "Decrypt: Output to " + sessionFile); } // openFileOutput creates a file in /data/data/{packagename}/files/ // In our case, /data/data/org.openintents.safe/files/ // This file is owned and only readable by our application os = ctx.openFileOutput(sessionFile, Context.MODE_PRIVATE); // after writing the decrypted content to a temporary file, // pass back a Uri that can be used to read back the contents resultUri = Uri.withAppendedPath(CryptoContentProvider.CONTENT_URI, "decrypt/" + decryptSession); result = decryptStreamWithSessionKey(is, os); // Close the input stream is.close(); os.close(); } catch (FileNotFoundException e) { Log.e(TAG, "File not found", e); } catch (IOException e) { Log.e(TAG, "IOException", e); } if (result == false) { resultUri = null; // Unsuccessful. Clean up ctx.deleteFile(sessionFile); } return resultUri; }
From source file:com.siviton.huanapi.data.HuanApi.java
private String getMD5(String string) { byte[] hash = null; try {// w w w . ja va 2s . c o m hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8")); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } StringBuilder hex = new StringBuilder(hash.length * 2); for (byte b : hash) { if ((b & 0xFF) < 0x10) hex.append("0"); hex.append(Integer.toHexString(b & 0xFF)); } return hex.toString(); }
From source file:com.online.restful.UsersSrv.java
@GET @Produces({ MediaType.APPLICATION_ATOM_XML, MediaType.APPLICATION_JSON }) @Path("/insert") public String insert(@Context LinkBuilders linkProcessor, @Context UriInfo uriInfo) { String json = ""; String userName = uriInfo.getQueryParameters().get("user").get(0); String userInsertName = uriInfo.getQueryParameters().get("userinsert").get(0); String password = uriInfo.getQueryParameters().get("pass").get(0); String tel = uriInfo.getQueryParameters().get("tel").get(0); String idioma = uriInfo.getQueryParameters().get("idioma").get(0); String role = uriInfo.getQueryParameters().get("role").get(0); try {// w ww.j a v a 2s. co m password = Utils.createSHA(password); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return "{\"ok\":\"ko\"}"; } List<Users> userFounds = (List<Users>) getHibernateTemplate().find("from Users u where u.username = ?", userName); if (userFounds == null || userFounds.isEmpty()) return "{}"; Users userFound = userFounds.get(0); Users user = new Users(); user.setPassword(password); user.setUsername(userInsertName); user.setCompany(userFound.getCompany()); user.setTelNumber(tel); user.setIdioma(idiomaDao.load(idioma)); UserRole userRole = new UserRole(); if (role == null || role.equals("null")) { userRole = usersDao.loadRole(Constants.ROLE_CLIENT); } else if (role.equals("ROLE_SUPER_ADMIN")) { userRole = usersDao.loadRole(Constants.ROLE_SUPER_ADMIN); } else if (role.equals("ROLE_ADMIN")) { userRole = usersDao.loadRole(Constants.ROLE_ADMIN); } else { userRole = usersDao.loadRole(Constants.ROLE_CLIENT); } user.setUserRole(userRole); getHibernateTemplate().save(user); return "{\"ok\":\"ok\"}"; }
From source file:edu.ncsa.sstde.indexing.postgis.PostgisIndexer.java
protected PostgisIndexer(PostgisIndexerSettings settings) { this.settings = settings; try {//from ww w .j a v a2 s. c om DIGEST = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } }
From source file:org.dasein.cloud.atmos.AtmosMethod.java
private @Nonnull String sign(@Nonnull ProviderContext ctx, @Nonnull String stringToSign) throws InternalException { try {/*from w ww. ja va 2s.co m*/ Mac mac = Mac.getInstance("HmacSHA1"); mac.init(new SecretKeySpec(Base64.decodeBase64(new String(ctx.getAccessPrivate(), "utf-8")), "HmacSHA1")); return new String(Base64.encodeBase64(mac.doFinal(stringToSign.getBytes("UTF-8"))), "utf-8"); } catch (NoSuchAlgorithmException e) { logger.error(e); e.printStackTrace(); throw new InternalException(e); } catch (InvalidKeyException e) { logger.error(e); e.printStackTrace(); throw new InternalException(e); } catch (IllegalStateException e) { logger.error(e); e.printStackTrace(); throw new InternalException(e); } catch (UnsupportedEncodingException e) { logger.error(e); e.printStackTrace(); throw new InternalException(e); } }