Example usage for org.apache.commons.codec.digest DigestUtils sha256

List of usage examples for org.apache.commons.codec.digest DigestUtils sha256

Introduction

In this page you can find the example usage for org.apache.commons.codec.digest DigestUtils sha256.

Prototype

public static byte[] sha256(String data) 

Source Link

Usage

From source file:io.apiman.gateway.platforms.vertx3.verticles.ApiVerticle.java

public void authenticateBasic(JsonObject authInfo, Handler<AsyncResult<User>> resultHandler) {
    String username = authInfo.getString("username");
    String password = StringUtils
            .chomp(Base64.encodeBase64String(DigestUtils.sha256(authInfo.getString("password")))); // Chomp, Digest, Base64Encode
    String storedPassword = apimanConfig.getBasicAuthCredentials().get(username);

    if (storedPassword != null && password.equals(storedPassword)) {
        resultHandler.handle(Future.<User>succeededFuture(null));
    } else {//from  w w w  . j  a v a 2s  .com
        resultHandler.handle(Future.<User>failedFuture("Not such user, or password is incorrect."));
    }
}

From source file:com.ubergeek42.WeechatAndroid.utils.UntrustedCertificateDialog.java

public String getCertificateDescription() {
    String fingerprint;/*from  w w  w .j  a  v  a 2s  .co  m*/
    try {
        fingerprint = new String(Hex.encodeHex(DigestUtils.sha256(certificate.getEncoded())));
    } catch (CertificateEncodingException e) {
        fingerprint = getString(R.string.ssl_cert_dialog_unknown_fingerprint);
    }
    return getString(R.string.ssl_cert_dialog_description, certificate.getSubjectDN().getName(),
            certificate.getIssuerDN().getName(),
            DateFormat.getDateTimeInstance().format(certificate.getNotBefore()),
            DateFormat.getDateTimeInstance().format(certificate.getNotAfter()), fingerprint);
}

From source file:com.github.aynu.mosir.core.standard.util.CodecHelper.java

/**
 * SHA-256/* w w  w . j a  va  2 s  .c  o m*/
 * <dl>
 * <dt>?
 * <dd>SHA-256?????
 * </dl>
 * @param data 
 * @return ??
 */
public static byte[] sha256(final byte[] data) {
    return DigestUtils.sha256(data);
}

From source file:energy.usef.core.repository.SignedMessageHashRepositoryTest.java

@Test
public void testIsSignedContentHashNotPresent() {
    boolean foundMessage = repository.isSignedMessageHashAlreadyPresent(DigestUtils.sha256(HELLO_USEF_CONTENT));
    assertFalse(foundMessage);//from  ww w  . java2 s  . c o  m
}

From source file:energy.usef.core.endpoint.ReceiverEndpoint.java

/**
 * Sends a client message to a queue.//w  ww  . j av  a 2s  . co m
 *
 * @param messageText message
 * @param request {@link HttpServletRequest}
 * @return status
 */
@POST
@Path("/receiveMessage")
@Consumes(TEXT_XML)
public Response receiveMessage(String messageText, @Context HttpServletRequest request) {
    try {
        // verify that the signed message has not been received yet.
        incomingMessageVerificationService.checkSignedMessageHash(DigestUtils.sha256(messageText));

        // transform the text/xml to a SignedMessage message
        SignedMessage signedMessage = XMLUtil.xmlToMessage(messageText, SignedMessage.class,
                config.getBooleanProperty(ConfigParam.VALIDATE_INCOMING_XML).booleanValue());

        // Get original senders IP-address, both directly and from the proxy('s).
        String addresslist = request.getRemoteAddr() + "," + request.getRemoteHost();
        String address = request.getHeader("X-Forwarded-For");
        if (address != null) {
            addresslist += "," + address;
        }

        // check if the sender is allowed to send messages to this endpoint
        messageFilterService.filterMessage(signedMessage.getSenderDomain(), addresslist);

        // verify sender by trying to unsing message
        String unsignedContent = verifyMessage(signedMessage);
        LOGGER_CONFIDENTIAL.debug("Received msg: {} ", unsignedContent);

        Message message = (Message) XMLUtil.xmlToMessage(unsignedContent,
                config.getBooleanProperty(ConfigParam.VALIDATE_INCOMING_XML).booleanValue());

        incomingMessageVerificationService.validateMessageId(message.getMessageMetadata().getMessageID());
        incomingMessageVerificationService
                .validateMessageValidUntil(message.getMessageMetadata().getValidUntil());

        // Check if the metadata is correct and the participant exists
        incomingMessageVerificationService.validateSender(signedMessage, message);

        jmsService.sendMessageToInQueue(unsignedContent);

        return Response.status(OK)
                .entity("Correctly received msg " + unsignedContent + " and set in to the IN queue").build();

    } catch (BusinessException e) {
        LOGGER.warn(e.getMessage(), e);
        return createBusinessErrorResponse(e);
    } catch (TechnicalException e) {
        LOGGER.error(e.getMessage(), e);
        return createErrorResponse(e.getMessage());
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        return createErrorResponse("Unknown server problem occurred.");
    }
}

From source file:com.mycompany.monroelabsm.BoxKey.java

private void setDigest() throws NoSuchAlgorithmException, IOException {
    BCI bci = new BCI();
    this.digest = DigestUtils.sha256(this.seed.getSeed());
    //store private key in ECKey object
    BigInteger bigDig = new BigInteger(1, this.digest);
    ECKey ecKey = new ECKey(bigDig);
    //set creation time with utc of the timestamp
    ecKey.setCreationTimeSeconds(60 * Bitwise.getInt(seed.getTime(), 0));
    this.publicKey = B58.encode(ecKey.getPubKeyHash(), (byte) 0);
    this.privateKey = B58.encode(ecKey.getPrivKeyBytes(), (byte) -128);
    this.key = ecKey;
    this.currentBalance = bci.addressBalance(this.publicKey);
    this.targetBalance = this.seed.getDenominationByte() * bci.rateSatoshis();
}

From source file:energy.usef.core.model.Message.java

/**
 * Constructs a Message with the specified xml, dtoMessage and direction.
 *
 * @param xml the XML representation of the error.
 * @param dtoMessage a {@link energy.usef.core.data.xml.bean.message.Message}.
 * @param direction the {@link MessageDirection}.
 *//*from   ww w  .  ja  va2 s .c  om*/
public Message(String xml, energy.usef.core.data.xml.bean.message.Message dtoMessage,
        MessageDirection direction) {
    MessageMetadata messageMetadata = dtoMessage.getMessageMetadata();
    setCreationTime(DateTimeUtil.getCurrentDateTime());
    this.xml = xml;
    this.direction = direction;
    this.sender = messageMetadata.getSenderDomain();
    this.receiver = messageMetadata.getRecipientDomain();
    this.messageId = messageMetadata.getMessageID();
    this.conversationId = messageMetadata.getConversationID();
    this.messageType = messageMetadata.getPrecedence() != null
            ? MessageType.fromValue(messageMetadata.getPrecedence())
            : null;
    this.contentHash = DigestUtils.sha256(xml);
}

From source file:com.screenslicer.common.Crypto.java

private static String encodeHelper(String plainText, String encryptionKey) {
    if (plainText == null || encryptionKey == null) {
        return null;
    }//from w ww. java 2 s  .  c o m
    try {
        Cipher aesCipher = Cipher.getInstance("AES");
        aesCipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(DigestUtils.sha256(encryptionKey), "AES"));
        return Base64.encodeBase64String(aesCipher.doFinal(plainText.getBytes("utf-8")));
    } catch (Exception e) {
        return null;
    }
}

From source file:com.screenslicer.common.Crypto.java

private static String decodeHelper(String cipherText, String encryptionKey) {
    if (cipherText == null || encryptionKey == null) {
        return null;
    }//w  w  w  .j a v a2s . c om
    try {
        Cipher aesCipher = Cipher.getInstance("AES");
        aesCipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(DigestUtils.sha256(encryptionKey), "AES"),
                aesCipher.getParameters());
        return new String(aesCipher.doFinal(Base64.decodeBase64(cipherText)), "utf-8");
    } catch (Exception e) {
        return null;
    }
}

From source file:energy.usef.core.repository.MessageRepositoryTest.java

public static Message createMessage() {
    Message message = new Message();
    message.setCreationTime(new LocalDateTime());
    message.setXml("<xml/>");
    message.setMessageId(UUID.randomUUID().toString());
    message.setMessageType(MessageType.ROUTINE);
    message.setContentHash(DigestUtils.sha256("Hash of the message"));
    return message;
}