// Path: ESignCore/src/main/java/tr/gov/turkiye/esign/exception/SmartCardException.java
// public class SmartCardException extends Exception {
// 
//     public SmartCardException(String s, Throwable t) {
//         super(s, t);
//     }
// }
// 
// Path: ESignCore/src/main/java/tr/gov/turkiye/esign/support/ExceptionSupport.java
// public class ExceptionSupport {
// 
//     private static ResourceBundle bundle = null;
// 
//     public static String getValue(final String key) {
//         if (bundle == null) {
//             Locale locale = new Locale("tr", "TR");
//             bundle = ResourceBundle.getBundle("exception/SmartCardExceptions", locale);
//         }
//         return bundle.getString(key);
//     }
//     
// }


import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import tr.gov.turkiye.esign.exception.SmartCardException;
import tr.gov.turkiye.esign.support.ExceptionSupport;
     * @return the array of bytes for the resulting hash value
     * @throws tr.gov.turkiye.esign.exception.SmartCardException
     */
    public static byte[] digestSHA256(byte[] input) throws SmartCardException {
        // we do digesting outside the card, because some cards do not support on-card hashing
        MessageDigest digestEngine;
        try {
            digestEngine = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException ex) {
            throw new SmartCardException(ExceptionSupport.getValue("NoSuchAlgorithmException"), ex);
        }

        // we buffer the content to have it after hashing for the PKCS#7 content
        return digestEngine.digest(input);
    }

    /**
     * Performs a final update on the digest using the specified array of bytes,
     * then completes the digest computation.
     *
     * @param input the input to be updated before the digest is completed.
     * @return the array of bytes for the resulting hash value
     * @throws tr.gov.turkiye.esign.exception.SmartCardException
     */
    public static byte[] digestSHA1(byte[] input) throws SmartCardException {
        // we do digesting outside the card, because some cards do not support on-card hashing
        MessageDigest digestEngine;
        try {
            digestEngine = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException ex) {
// Path: ESignCore/src/main/java/tr/gov/turkiye/esign/exception/SmartCardException.java
// public class SmartCardException extends Exception {
// 
//     public SmartCardException(String s, Throwable t) {
//         super(s, t);
//     }
// }
// 
// Path: ESignCore/src/main/java/tr/gov/turkiye/esign/support/ExceptionSupport.java
// public class ExceptionSupport {
// 
//     private static ResourceBundle bundle = null;
// 
//     public static String getValue(final String key) {
//         if (bundle == null) {
//             Locale locale = new Locale("tr", "TR");
//             bundle = ResourceBundle.getBundle("exception/SmartCardExceptions", locale);
//         }
//         return bundle.getString(key);
//     }
//     
// }


// Path: ESignCore/src/main/java/tr/gov/turkiye/esign/util/Util.java
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.Principal;
import tr.gov.turkiye.esign.exception.SmartCardException;
import tr.gov.turkiye.esign.support.ExceptionSupport;

     * @return the array of bytes for the resulting hash value
     * @throws tr.gov.turkiye.esign.exception.SmartCardException
     */
    public static byte[] digestSHA256(byte[] input) throws SmartCardException {
        // we do digesting outside the card, because some cards do not support on-card hashing
        MessageDigest digestEngine;
        try {
            digestEngine = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException ex) {
            throw new SmartCardException(ExceptionSupport.getValue("NoSuchAlgorithmException"), ex);
        }

        // we buffer the content to have it after hashing for the PKCS#7 content
        return digestEngine.digest(input);
    }

    /**
     * Performs a final update on the digest using the specified array of bytes,
     * then completes the digest computation.
     *
     * @param input the input to be updated before the digest is completed.
     * @return the array of bytes for the resulting hash value
     * @throws tr.gov.turkiye.esign.exception.SmartCardException
     */
    public static byte[] digestSHA1(byte[] input) throws SmartCardException {
        // we do digesting outside the card, because some cards do not support on-card hashing
        MessageDigest digestEngine;
        try {
            digestEngine = MessageDigest.getInstance("SHA-1");
        } catch (NoSuchAlgorithmException ex) {
            throw new SmartCardException(ExceptionSupport.getValue("NoSuchAlgorithmException"), ex);