List of usage examples for java.security InvalidKeyException printStackTrace
public void printStackTrace()
From source file:org.toobsframework.util.Crypto.java
protected Crypto() { try {/*ww w. j a v a2 s .c o m*/ DESKeySpec keySpec = new DESKeySpec(keyData); SecretKey key = SecretKeyFactory.getInstance(ALGORITHM).generateSecret(keySpec); initEncryptCipher(key); initDecryptCipher(key); } catch (InvalidKeyException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidKeySpecException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.wattdepot.server.StrongAES.java
/** * @param plainText the plain text to encrypt. * @return the encrypted text.//www . ja v a 2s . c om */ public String encrypt(String plainText) { String cipherText = null; try { this.cipher.init(Cipher.ENCRYPT_MODE, this.key); cipherText = Base64.encodeBase64String(cipher.doFinal(plainText.getBytes())); } catch (InvalidKeyException e) { // NOPMD // not sure what to do. e.printStackTrace(); } catch (IllegalBlockSizeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BadPaddingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return cipherText; }
From source file:org.wattdepot.server.StrongAES.java
/** * @param cipherText the encrypted string. * @return the decrypted string.// ww w .ja v a 2 s.com */ public String decrypt(String cipherText) { String plainText = null; try { this.cipher.init(Cipher.DECRYPT_MODE, this.key); plainText = new String(cipher.doFinal(Base64.decodeBase64(cipherText))); } catch (InvalidKeyException e) { // NOPMD // not sure what to do. e.printStackTrace(); } catch (IllegalBlockSizeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BadPaddingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return plainText; }
From source file:com.aqnote.shared.cryptology.symmetric.Blowfish.java
/** * ?//w w w .ja v a 2s .c om * * @param cipher Cipher * @param opmode operation mode (ENCRYPT_MODE?DECRYPT_MODE?WRAP_MODE UNWRAP_MODE) * @param key Key * @param iv AlgorithmParameterSpec */ private void initCipher(Cipher cipher, int opmode, Key key, AlgorithmParameterSpec paramSpec) { try { cipher.init(opmode, key, paramSpec); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (InvalidAlgorithmParameterException e) { e.printStackTrace(); } }
From source file:org.broadleafcommerce.payment.service.gateway.AuthorizeNetTransparentRedirectServiceImpl.java
public PaymentResponseDTO common(PaymentRequestDTO requestDTO, Boolean submitForSettlement) { Assert.isTrue(requestDTO.getOrderId() != null, "Must pass an OrderId value on the Payment Request DTO"); Assert.isTrue(requestDTO.getTransactionTotal() != null, "Must pass a Transaction Total value on the Payment Request DTO"); String apiLoginId = configuration.getLoginId(); String transactionKey = configuration.getTransactionKey(); String relayResponseURL = configuration.getResponseUrl(); String merchantTransactionVersion = configuration.getTransactionVersion(); String xTestRequest = configuration.getXTestRequest(); String serverUrl = configuration.getServerUrl(); String custId = requestDTO.getCustomer().getCustomerId(); String orderId = requestDTO.getOrderId(); Fingerprint fingerprint = Fingerprint.createFingerprint(apiLoginId, transactionKey, System.currentTimeMillis(), requestDTO.getTransactionTotal()); PaymentResponseDTO responseDTO = new PaymentResponseDTO(PaymentType.CREDIT_CARD, AuthorizeNetGatewayType.AUTHORIZENET) .responseMap(AuthNetField.X_INVOICE_NUM.getFieldName(), System.currentTimeMillis() + "") .responseMap(AuthNetField.X_RELAY_URL.getFieldName(), relayResponseURL) .responseMap(AuthNetField.X_LOGIN.getFieldName(), apiLoginId) .responseMap(AuthNetField.X_FP_SEQUENCE.getFieldName(), fingerprint.getSequence() + "") .responseMap(AuthNetField.X_FP_TIMESTAMP.getFieldName(), fingerprint.getTimeStamp() + "") .responseMap(AuthNetField.X_FP_HASH.getFieldName(), fingerprint.getFingerprintHash()) .responseMap(AuthNetField.X_VERSION_FIELD.getFieldName(), merchantTransactionVersion) .responseMap(AuthNetField.X_METHOD.getFieldName(), "CC") .responseMap(AuthNetField.X_TYPE.getFieldName(), submitForSettlement ? AUTH_CAPTURE : AUTH_ONLY) .responseMap(AuthNetField.X_AMOUNT.getFieldName(), requestDTO.getTransactionTotal()) .responseMap(AuthNetField.X_TEST_REQUEST.getFieldName(), xTestRequest) .responseMap(AuthNetField.X_RELAY_RESPONSE.getFieldName(), "true") .responseMap(AuthNetField.X_CUST_ID.getFieldName(), custId) .responseMap(AuthNetField.X_TRANS_ID.getFieldName(), orderId) .responseMap(MessageConstants.BLC_CID, custId) .responseMap(MessageConstants.BLC_OID, orderId) .responseMap(MessageConstants.AUTHORIZENET_SERVER_URL, serverUrl); if (requestDTO.billToPopulated()) { responseDTO/*from www.j a v a 2 s . c o m*/ .responseMap(AuthNetField.X_FIRST_NAME.getFieldName(), requestDTO.getBillTo().getAddressFirstName()) .responseMap(AuthNetField.X_LAST_NAME.getFieldName(), requestDTO.getBillTo().getAddressLastName()) .responseMap(AuthNetField.X_ADDRESS.getFieldName(), requestDTO.getBillTo().getAddressLine1()) .responseMap(AuthNetField.X_CITY.getFieldName(), requestDTO.getBillTo().getAddressCityLocality()) .responseMap(AuthNetField.X_STATE.getFieldName(), requestDTO.getBillTo().getAddressStateRegion()) .responseMap(AuthNetField.X_ZIP.getFieldName(), requestDTO.getBillTo().getAddressPostalCode()) .responseMap(AuthNetField.X_COUNTRY.getFieldName(), requestDTO.getBillTo().getAddressCountryCode()) .responseMap(AuthNetField.X_EMAIL.getFieldName(), requestDTO.getBillTo().getAddressEmail() != null ? requestDTO.getBillTo().getAddressEmail() : requestDTO.getCustomer().getEmail()) .responseMap(AuthNetField.X_PHONE.getFieldName(), requestDTO.getBillTo().getAddressPhone()); } for (String fieldKey : requestDTO.getAdditionalFields().keySet()) { responseDTO.responseMap(fieldKey, (String) requestDTO.getAdditionalFields().get(fieldKey)); } try { responseDTO.responseMap(MessageConstants.BLC_TPS, authorizeNetCheckoutService.createTamperProofSeal(custId, orderId)); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return responseDTO; }
From source file:dz.alkhwarizmix.framework.java.utils.CryptoUtil.java
/** * encryptString/* w w w . j a v a2 s.c o m*/ */ public final String encryptString(String stringToEncrypt) { String result = null; byte[] dataToEncrypt = null; byte[] encrypted = null; dataToEncrypt = hex2Byte(stringToHex(stringToEncrypt)); try { cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec); encrypted = cipher.doFinal(dataToEncrypt); result = byte2hex(encrypted); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (InvalidAlgorithmParameterException e) { e.printStackTrace(); } return result; }
From source file:dz.alkhwarizmix.framework.java.utils.CryptoUtil.java
/** * decryptString/*from ww w . j av a 2 s .co m*/ */ public final String decryptString(String hexStringToDecrypt) { String result = null; byte[] dataToDecrypt = null; byte[] decrypted = null; dataToDecrypt = hex2Byte(hexStringToDecrypt); try { cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, ivParameterSpec); decrypted = cipher.doFinal(dataToDecrypt); result = hexToString(byte2hex(decrypted)); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (InvalidAlgorithmParameterException e) { e.printStackTrace(); } return result; }
From source file:com.fegor.alfresco.action.DecipherContent.java
/** * Scan file for nodeRef/*from w w w . j a v a 2 s . c o m*/ * * @param nodeRef * @throws DecoderException * @throws InvalidAlgorithmParameterException */ private void cryptoFileDecipher(NodeRef nodeRef) throws InvalidAlgorithmParameterException, DecoderException { ContentReader contentReader = this.contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); ContentWriter contentWriter = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); if (contentReader != null) { byte[] crb = contentReader.getContentString().getBytes(); Crypto crypto = new Crypto(); crypto.setPassword(this.password); this.salt = (String) nodeService.getProperty(nodeRef, AlfCryptoModel.PROP_SALT); this.vector_init = (String) nodeService.getProperty(nodeRef, AlfCryptoModel.PROP_VECTOR_INIT); try { crypto.configDecrypt(this.vector_init, this.salt); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (InvalidKeySpecException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } try { crypto.setInput(Base64.decode(crb)); } catch (Base64DecoderException e1) { e1.printStackTrace(); } try { crypto.Decipher(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (ShortBufferException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } contentWriter.setMimetype("text/plain"); contentWriter.putContent((InputStream) (new ByteArrayInputStream(crypto.getOutput()))); this.removeAspect(nodeRef); this.addAspect(nodeRef); } else { if (logger.isDebugEnabled()) logger.debug(this.getClass().getName() + ": [contentReader is null]"); } }
From source file:com.fegor.alfresco.action.CipherContent.java
/** * Crypto file for nodeRef//from w w w . ja v a2s . c o m * * @param nodeRef * @throws IOException * @throws ContentIOException */ private void cryptoFileCipher(NodeRef nodeRef) throws ContentIOException, IOException { ContentReader contentReader = this.contentService.getReader(nodeRef, ContentModel.PROP_CONTENT); ContentWriter contentWriter = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true); if (contentReader != null) { Crypto crypto = new Crypto(); crypto.setPassword(this.password); byte[] crb = IOUtils.toByteArray(contentReader.getContentInputStream()); try { crypto.configEncrypt(); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (InvalidKeySpecException e) { e.printStackTrace(); } catch (NoSuchPaddingException e) { e.printStackTrace(); } catch (InvalidParameterSpecException e) { e.printStackTrace(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } crypto.setInput(crb); try { crypto.Cipher(); } catch (IllegalBlockSizeException e) { e.printStackTrace(); } catch (BadPaddingException e) { e.printStackTrace(); } catch (ShortBufferException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } contentWriter.putContent(Base64.encode(crypto.getOutput())); this.salt = crypto.getSalt(); this.vector_init = crypto.getVectorInit(); this.removeAspect(nodeRef); this.addAspect(nodeRef); } else { if (logger.isDebugEnabled()) logger.debug(this.getClass().getName() + ": [contentReader is null]"); } }
From source file:com.aqnote.shared.cryptology.asymmetric.DSA.java
/** * ???// w w w.ja va 2 s. c o m * * @param content ???? * @param keyPairName key pair * @return base64??? */ public String sign(byte[] content, String keyPairName) throws RuntimeException { KeyPairEntry entry = (KeyPairEntry) keyPairs.get(keyPairName); if (entry == null || entry.privateKey == null) { return null; } try { Signature signature = Signature.getInstance(ALGORITHM); signature.initSign(entry.privateKey); signature.update((byte[]) content); byte[] signed = signature.sign(); if (log.isDebugEnabled()) { log.debug("Java signature[length=" + signed.length + "]: " + toHexString(signed)); } return Base64.encodeBase64String(signed); } catch (InvalidKeyException e) { e.printStackTrace(); } catch (SignatureException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return null; }