Example usage for javax.xml.bind DatatypeConverter parseBase64Binary

List of usage examples for javax.xml.bind DatatypeConverter parseBase64Binary

Introduction

In this page you can find the example usage for javax.xml.bind DatatypeConverter parseBase64Binary.

Prototype

public static byte[] parseBase64Binary(String lexicalXSDBase64Binary) 

Source Link

Document

Converts the string argument into an array of bytes.

Usage

From source file:org.zstack.test.mevoco.TestLicense.java

@Test
public void test() throws Exception {
    File licpath = PathUtil.findFileOnClassPath("license.txt", true);
    File privpath = PathUtil.findFileOnClassPath("priv.key", true);
    File capath = PathUtil.findFileOnClassPath("ca.pem", true);

    FileInputStream lic = new FileInputStream(licpath);
    FileInputStream priv = new FileInputStream(privpath);
    FileInputStream ca = new FileInputStream(capath);

    //SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
    //Date d = f.parsed("2015-12-30T11:25:22+08:00", new ParsePosition(0));
    //DateFormat df = DateFormat.getDateInstance();
    //Date d = df.parse("2015-12-30T11:25:22+08:00");
    //System.out.println(d.toString());

    DateTime d = new DateTime("2015-12-30T11:25:22+08:00");
    System.out.println(d.toString());

    LicenseChecker checker = new LicenseChecker(lic, priv, ca);
    LicenseInfo info = checker.getLicenseInfo();

    System.out.println("user: " + info.getUser());
    System.out.println("hostnum: " + info.getHostNum());
    System.out.println("type: " + info.getLicenseType());
    System.out.println("issue time: " + info.getIssueTime());
    System.out.println("expired time: " + info.getExpireTime());

    for (Object o : info.getThumbprint().entrySet()) {
        Map.Entry pair = (Map.Entry) o;
        System.out.println(pair.getKey() + " = " + pair.getValue());
    }// w  w w . j  ava  2s .  c o m

    ca.close();
    priv.close();
    lic.close();

    String pkey = FileUtils.readFileToString(privpath);
    String licreq = "eyJ0aHVtYnByaW50IjoiZXlKMlpYSnphVzl1SWpvaU1DNHhJaXdpYUc5emRHNWhiV1VpT2lKc2IyTmhiR2h2YzNRaUxDSmpjSFZ6SWpvaU5DSXNJbU53ZFcxdlpHVnNJam9pU1c1MFpXd29VaWtnUTI5eVpTaFVUU2tnYVRjdE5qVXdNRlVnUTFCVklFQWdNaTQxTUVkSWVpSXNJbTFsYldsdWEySWlPaUkwTURNek5qTTJJbjA9IiwicHVia2V5IjoiLS0tLS1CRUdJTiBSU0EgUFVCTElDIEtFWS0tLS0tXG5NSUlCSERBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVFrQU1JSUJCQUtCL0Rmd1I2c0NGZDVleDdWcHpYa2dLd25zXG4rKzhyWElkblBKQ0swaStvaHVVUWl5b1hKUnhwMmJqZXJsM1JSbW1WeGtjMlRQeU1xWjVhR0hMMElpdHhPVlVkXG5JcmtHblFVeHEyc2JGRHJIVXplNHA0MWtRWStWbTB4REo1Tmk0bTRQZUp4eDVBVkNaMkVCSzN0RlA2REl4R0ZpXG5VUDdvMGdGeFhLU1VvVzFncFhITjNpbUJSUWh5cEYrQldmQ0pmeThSL2tPbGI1KytCZHovc2EvRzByMTNHQU5aXG5qUkZuVFhSMDZoaWd3TzI2a0ttcTlsdDd2UVNaSXpGaDJVbzZGdzlIL0M3bkk2U00rZDE4R3drdXVNUUIyZFZVXG55S2FkK1h3dE1xN1JqT2xrdGdUcE56SEpMa05IdUJHcEZveE1yLzRtdUxKYVRCUHdSR202M1VqMWp3SURBUUFCXG4tLS0tLUVORCBSU0EgUFVCTElDIEtFWS0tLS0tXG4ifQ==";
    Map<String, String> m = new HashMap<String, String>();
    m.put("privateKey", pkey);
    m.put("license", licreq);
    String jstr = JSONObjectUtil.toJsonString(m);
    String encoded = DatatypeConverter.printBase64Binary(jstr.getBytes());
    System.out.println(encoded);
    byte[] decoded = DatatypeConverter.parseBase64Binary(encoded);
    String jstr1 = new String(decoded);
    System.out.println(jstr1);
    m = JSONObjectUtil.toObject(jstr1, HashMap.class);
    System.out.println(m.get("privateKey"));
    System.out.println(m.get("license"));
}

From source file:pt.lsts.neptus.plugins.sunfish.awareness.ArgosLocationProvider.java

private String getArgosPassword() {
    if (argosPassword == null)
        return "";
    return StringUtils.newStringUtf8(DatatypeConverter.parseBase64Binary(argosPassword));
}

From source file:pt.lsts.neptus.util.credentials.Credentials.java

/**
 * @return the (plain) selected login password 
 *///from  w  ww .j av  a  2s. c  o  m
public String getPassword() {
    if (password == null)
        return "";
    return StringUtils.newStringUtf8(DatatypeConverter.parseBase64Binary(password));
}

From source file:sd.code.stagent.fileservices.ReceiveFile.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
 *
 * @param request servlet request// www.  j  a v a2 s.c o  m
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        String requestText;
        requestText = Web.readClient(request);
        try {

            JSONParser parser = new JSONParser();

            JSONObject obj = (JSONObject) parser.parse(requestText);

            String filename = obj.get("filename").toString();
            String dir = obj.get("dir").toString();

            boolean needConversion = filename.contains(".wav");
            String toDir = dir;

            if (needConversion) {
                toDir = "/tmp/";
            }
            File file = new File(toDir + filename);
            FileOutputStream writer = new FileOutputStream(file);

            // Read parts

            JSONArray contents = (JSONArray) obj.get("content");
            for (int i = 0; i < contents.size(); i++) {
                String part = contents.get(i).toString();
                byte[] decoded = DatatypeConverter.parseBase64Binary(part);
                writer.write(decoded);
            }

            writer.close();

            // Conversion
            if (needConversion) {
                Shell.executeShell("sox " + toDir + filename + " " + dir
                        + filename.substring(0, filename.indexOf(".")) + ".gsm");
            }

            out.println("File " + filename + " has been written");

        } catch (Exception ex) {
            System.out.println(ex.toString());
            out.println("ErrirL : :" + ex.toString());
        }

    }
}

From source file:se.nrm.bio.mediaserver.rs.MediaResourceForm.java

/**
 * 2014-10-23 : temporary fix. Created for migration of NRM-data, problem
 * with UTF-8//  w  w  w .  j  av  a2  s .  co  m
 *
 * @param form
 * @return
 */
@POST
@Path("/upload-file/base64")
@Consumes(MediaType.APPLICATION_JSON)
//    @Interceptors(ContentTypeSetterPreProcessorInterceptor.class)
public Response createNewMediaFile_JSON(FileUploadJSON form) {
    String mimeType = "unknown", hashChecksum = "unknown";

    String fileDataBase64 = form.getFileDataBase64();
    final byte[] fileData = DatatypeConverter.parseBase64Binary(fileDataBase64);
    if (null == fileData || fileData.length == 0) {
        String msg = "attribute 'fileData' is null or empty \n";
        logger.info(msg);
        return Response.status(STATUS_INTERNAL_SERVER_ERROR).entity(msg).build();
    }

    String fileUUID = generateRandomUUID();
    String uploadedFileLocation = getAbsolutePathToFile(fileUUID);
    writeBase64ToFile(fileData, uploadedFileLocation);

    Tika tika = new Tika();
    mimeType = tika.detect(fileData);

    Media media = null;
    switch (mimeType) {
    case "image/tiff":
        logger.info("mediatype - image/tiff");
    case "image/png":
    case "image/jpeg":
    case "image/gif": {
        //                boolean exportImage = form.getExport();
        boolean exportImage = false;
        String exifJSON = "N/A";
        String isExif = (String) envMap.get("is_exif");
        if (Boolean.parseBoolean(isExif)) {
            try {
                exifJSON = extractExif(uploadedFileLocation, exifJSON);
            } catch (ImageProcessingException ex) {
                logger.info(ex);
            } catch (IOException ex) {
                logger.info(ex);
            }
        }
        media = MediaFactory.createImage2(exportImage, exifJSON);
        break;
        //                boolean exportImage = form.getExport();
        //                media = MediaFactory.createImage(exportImage);
        //                break;
    }
    case "video/quicktime":
    case "video/mp4": {
        String startTime = form.getStartTime(), endTime = form.getEndTime();
        media = MediaFactory.createVideo(checkStartEndTime(startTime), checkStartEndTime(endTime));
        break;
    }
    case "audio/mpeg":
    case "audio/vorbis":
    case "audio/ogg": {
        String startTime = form.getStartTime(), endTime = form.getEndTime();
        media = MediaFactory.createSound(checkStartEndTime(startTime), checkStartEndTime(endTime));
        break;
    }
    case "application/pdf": {
        media = MediaFactory.createAttachement();
        break;
    }
    }

    if (null == media) {
        String msg = String.format("Mimetype [ %s ] is not supported \n", mimeType);
        logger.info("media is null:  ");
        return Response.status(STATUS_INTERNAL_SERVER_ERROR).entity(msg).build();
    }

    hashChecksum = CheckSumFactory.createMD5ChecksumFromBytestream(fileData);

    String pathToMedia = (String) envMap.get("relative_stream_url");

    media.setUuid(fileUUID);
    media.setOwner(form.getOwner());
    media.setFilename(form.getFileName());
    media.setMimetype(mimeType);
    media.setVisibility(form.getAccess());
    media.setHash(hashChecksum);
    media.setMediaURL(pathToMedia.concat("/").concat(fileUUID));

    if (form.getTags() != null) {
        String tags = form.getTags();
        if (!tags.equals("")) {
            addingTags(media, tags);
        }
    }

    if (form.getLegend() == null || form.getLegend().equals("")) {
        form.setLegend("N/A");
    }

    if (form.getLegend() != null && !form.getLegend().equals("")) {
        MediaText mediaText;
        String comment = form.getComment();
        if (comment != null) {
            mediaText = new MediaText(form.getLegend(), form.getLanguage(), media, comment);
        } else {
            mediaText = new MediaText(form.getLegend(), form.getLanguage(), media);
        }
        media.addMediaText(mediaText);
    }

    final String licenceType = form.getLicenseType();
    if (licenceType != null) {
        Lic license = fetchFromDB(licenceType);
        media.getLics().add(license);
    }

    writeToDatabase(media);
    String responseOutput = fileUUID;

    Response build = Response.status(dynamic_status).header("mediaUUID", responseOutput).entity(responseOutput)
            .build();

    return build;
}

From source file:se.nrm.bio.mediaserver.rs.NewMediaResourceForm.java

/**
 * curl -v -H "Accept: application/json" -H "Content-type: application/json"
 * -X POST -d @meta_and_image.json/*from   w  w w .  ja v  a 2s.c o  m*/
 * http://127.0.0.1:8080/MediaServerResteasy/media
 *
 * @param form with base64-encoding.
 * @return
 */
@POST
@Path("")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createMedia(FileUploadJSON form) {
    String mimeType = "unknown", hashChecksum = "unknown";
    String msg = "attribute 'fileData' is null or empty \n";
    // Check, howto avoid long-stacktrace if file is forgotten ?
    if (form == null) {
        logger.debug(msg);
        return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
    }
    String fileDataBase64 = form.getFileDataBase64();
    if (null == fileDataBase64 || fileDataBase64.isEmpty()) {
        logger.debug(msg);
        return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
    }
    byte[] fileData = DatatypeConverter.parseBase64Binary(fileDataBase64);

    if (null == fileData || fileData.length == 0) {
        logger.debug(msg);
        return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
    }

    String fileUUID = generateRandomUUID();
    String uploadedFileLocation = getAbsolutePathToFile(fileUUID);
    writeBase64ToFile(fileData, uploadedFileLocation);

    Tika tika = new Tika();
    mimeType = tika.detect(fileData);

    Media media = null;
    String mediaType = mimeType.substring(0, mimeType.indexOf("/"));

    switch (mediaType) {
    case "image": {
        boolean exportImage = form.getExport();
        String exifJSON = "N/A";
        String isExif = (String) envMap.get("is_exif");
        if (Boolean.parseBoolean(isExif)) {
            try {
                exifJSON = extractExif(uploadedFileLocation, exifJSON);
            } catch (ImageProcessingException | IOException ex) {
                logger.info(ex);
            }
        }
        media = MediaFactory.createImage2(exportImage, exifJSON);
        break;
    }
    case "video": {
        String startTime = form.getStartTime(), endTime = form.getEndTime();
        media = MediaFactory.createVideo(checkStartEndTime(startTime), checkStartEndTime(endTime));
        break;
    }
    case "audio": {
        String startTime = form.getStartTime(), endTime = form.getEndTime();
        media = MediaFactory.createSound(checkStartEndTime(startTime), checkStartEndTime(endTime));
        break;
    }
    case "text":
    case "application": {
        media = MediaFactory.createAttachement();
        break;
    }
    }

    if (null == media) {
        logger.info("media is null:  ");
        return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
    }

    hashChecksum = CheckSumFactory.createMD5ChecksumFromBytestream(fileData);

    media.setUuid(fileUUID);
    media.setOwner(form.getOwner());
    media.setFilename(form.getFileName());
    media.setMimetype(mimeType);
    media.setVisibility(form.getAccess());
    media.setHash(hashChecksum);
    final String mediaURL = createMediaURL(fileUUID, mimeType);
    media.setMediaURL(mediaURL);

    if (form.getTaggar() != null) {
        String[] taggar = form.getTaggar();
        String splitter = TagHelper.getSplitter();
        String joinTags = StringUtils.join(taggar, splitter);
        addingTags(media, joinTags);
    }

    final String legend = form.getLegend();
    if (legend == null || legend.isEmpty()) {
        form.setLegend("N/A");
    }

    if (legend != null && !legend.isEmpty()) {
        MediaText mediaText;
        String comment = form.getComment();
        if (comment != null) {
            mediaText = new MediaText(legend, form.getLanguage(), media, comment);
        } else {
            mediaText = new MediaText(legend, form.getLanguage(), media);
        }
        media.addMediaText(mediaText);
    }

    final String licenceType = form.getLicenseType();
    if (licenceType != null) {
        Lic license = fetchNewLicenseFromDB(licenceType); // enhanced with version, check the liquibase ( foreign key constraints)
        media.getLics().add(license);
    }

    writeToDatabase(media);
    Response response = Response.status(Response.Status.CREATED).entity(media).build();

    return response;
}

From source file:se.nrm.bio.mediaserver.rs.NewMediaResourceForm.java

/**
 * @param form with base64-encoding./*ww  w. ja v  a  2s .  c o  m*/
 * @return 
 */
@PUT
@Path("")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateMedia(FileUploadJSON form) {

    String mediaUUID = form.getMediaUUID();
    if (null == mediaUUID) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }

    Media media = (Media) bean.get(mediaUUID);
    if (null == media) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }

    String base64EncodedFile = form.getFileDataBase64();
    if (base64EncodedFile != null) {
        final byte[] fileData = DatatypeConverter.parseBase64Binary(base64EncodedFile);
        String uploadedFileLocation = getAbsolutePathToFile(mediaUUID);
        writeBase64ToFile(fileData, uploadedFileLocation);

        Tika tika = new Tika();
        String mimeType = tika.detect(fileData);
        media.setMimetype(mimeType);
        final String mediaURL = createMediaURL(mediaUUID, mimeType);
        media.setMediaURL(mediaURL);
    }

    // fetch from form.
    String alt = form.getAlt(), access = form.getAccess(), fileName = form.getFileName();
    String legend = form.getLegend(), owner = form.getOwner(); //  tags = form.getTags();

    String[] tags = form.getTaggar();

    String comment = form.getComment();
    String licenceType = form.getLicenseType();

    if (alt != null && !alt.isEmpty()) {
        media.setAlt(alt);
    }

    if (access != null && !access.isEmpty()) {
        media.setVisibility(access);
    }

    if (fileName != null && !fileName.isEmpty()) {
        media.setFilename(fileName);
    }

    if (legend != null && !legend.isEmpty()) {
        String language = form.getLanguage();
        MediaText mediatext = new MediaText(legend, language, media, comment);
        // kan frenklas . iner:2014-08-26
        updateMediatext(mediatext, media);
    }

    if (licenceType != null && !licenceType.isEmpty()) {
        updateLicense(licenceType, media);
    }

    if (owner != null && !owner.isEmpty()) {
        media.setOwner(owner);
    }

    //        if (tags != null && !tags.isEmpty()) {
    //            media.setTaggar(tags);
    //        }
    if (media instanceof Image) {
        Boolean export = form.getExport();
        if (export != null) {
            Image image = (Image) media;
            image.setIsExported(export);
            media = image;
        }

    } else if (media instanceof Stream) {
        String startTime = form.getStartTime(), endTime = form.getEndTime();
        Stream stream = (Stream) media;
        if (startTime != null && !startTime.isEmpty()) {
            stream.setStartTime(Integer.parseInt(startTime));
        }
        if (endTime != null && !endTime.isEmpty()) {
            stream.setStartTime(Integer.parseInt(endTime));
        }
        media = stream;

    } else if (media instanceof Attachment) {

    }

    writeToDatabase(media);
    Response response = Response.status(Response.Status.OK).entity(media).build();

    return response;
}

From source file:se.nrm.mediaserver.resteasy.MediaResourceForm.java

/**
 * 2014-10-23 : temporary fix. Created for migration of NRM-data, problem
 * with UTF-8/*  w  w w  .  ja v a  2  s .c  om*/
 *
 * @param form
 * @return
 * @throws java.io.IOException
 */
@POST
@Path("/upload-file/base64")
@Consumes("application/json")
//    @Interceptors(ContentTypeSetterPreProcessorInterceptor.class)
public Response createNewMediaFile_JSON(FileUploadJSON form) throws IOException {

    String mimeType = "unknown", hashChecksum = "unknown";

    final byte[] fileData = DatatypeConverter.parseBase64Binary(form.getFileDataBase64());
    if (null == fileData || fileData.length == 0) {
        String msg = "attribute 'fileData' is null or empty \n";
        logger.info(msg);
        return Response.status(STATUS_INTERNAL_SERVER_ERROR).entity(msg).build();
    }

    String fileUUID = generateRandomUUID();
    String uploadedFileLocation = getAbsolutePathToFile(fileUUID);
    writeBase64ToFile(fileData, uploadedFileLocation);

    Tika tika = new Tika();
    mimeType = tika.detect(fileData);

    Media media = null;
    switch (mimeType) {
    case "image/tiff":
        logger.info("mediatype - image/tiff");
    case "image/png":
    case "image/jpeg":
    case "image/gif": {
        boolean exportImage = form.getExport();
        String exifJSON = "N/A";
        boolean isExif = AdminProperties.getIsExif();
        if (isExif) {
            try {
                exifJSON = extractExif(uploadedFileLocation, exifJSON);
            } catch (ImageProcessingException ex) {
                logger.info(ex);
            }
        }
        media = MediaFactory.createImage2(exportImage, exifJSON);
        break;
        //                boolean exportImage = form.getExport();
        //                media = MediaFactory.createImage(exportImage);
        //                break;
    }
    case "video/quicktime":
    case "video/mp4": {
        String startTime = form.getStartTime(), endTime = form.getEndTime();
        media = MediaFactory.createVideo(checkStartEndTime(startTime), checkStartEndTime(endTime));
        break;
    }
    case "audio/mpeg":
    case "audio/vorbis":
    case "audio/ogg": {
        String startTime = form.getStartTime(), endTime = form.getEndTime();
        media = MediaFactory.createSound(checkStartEndTime(startTime), checkStartEndTime(endTime));
        break;
    }
    case "application/pdf": {
        media = MediaFactory.createAttachement();
        break;
    }
    }

    if (null == media) {
        String msg = String.format("Mimetype [ %s ] is not supported \n", mimeType);
        logger.info("media is null:  ");
        return Response.status(STATUS_INTERNAL_SERVER_ERROR).entity(msg).build();
    }

    hashChecksum = CheckSumFactory.createMD5ChecksumFromBytestream(fileData);

    MediaURL url = new MediaURL();
    String pathToMedia = url.getPathToStream();

    media.setUuid(fileUUID);
    media.setOwner(form.getOwner());
    media.setFilename(form.getFileName());
    media.setMimetype(mimeType);
    media.setVisibility(form.getAccess());
    media.setHash(hashChecksum);
    media.setMediaURL(pathToMedia.concat(fileUUID));

    if (form.getTags() != null) {
        String tags = form.getTags();
        if (!tags.equals("")) {
            addingTags(media, tags);
        }
    }

    if (form.getLegend() == null || form.getLegend().equals("")) {
        form.setLegend("N/A");
    }

    if (form.getLegend() != null && !form.getLegend().equals("")) {
        MediaText mediaText;
        String comment = form.getComment();
        if (comment != null) {
            mediaText = new MediaText(form.getLegend(), form.getLanguage(), media, comment);
        } else {
            mediaText = new MediaText(form.getLegend(), form.getLanguage(), media);
        }
        media.addMediaText(mediaText);
    }

    final String licenceType = form.getLicenseType();
    if (licenceType != null) {
        Lic license = fetchFromDB(licenceType);
        media.getLics().add(license);
    }

    writeToDatabase(media);
    String responseOutput = fileUUID;

    Response build = Response.status(dynamic_status).header("mediaUUID", responseOutput).entity(responseOutput)
            .build();

    return build;
}

From source file:tds.itemrenderer.security.Encryption.java

private synchronized String decrypt(final String stringToDecrypt) {
    try {// w w w.java 2 s . c o  m
        if (StringUtils.isEmpty(stringToDecrypt)) {
            return "";
        }

        byte[] encryptedBytes = DatatypeConverter.parseBase64Binary(stringToDecrypt);

        byte[] iv = new byte[IV_LENGTH];
        System.arraycopy(encryptedBytes, 0, iv, 0, iv.length);
        decryptCipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iv));
        byte[] cipherBytes = new byte[encryptedBytes.length - IV_LENGTH];
        System.arraycopy(encryptedBytes, IV_LENGTH, cipherBytes, 0, cipherBytes.length);
        byte[] decryptedBytes = decryptCipher.doFinal(cipherBytes);
        return new String(decryptedBytes, UTF_8);
    } catch (InvalidAlgorithmParameterException e) {
        log.error("Encyption.decrypt: " + e.getMessage(), e);
        throw new TDSEncryptionException("Algorithm is not valid");
    } catch (InvalidKeyException e) {
        log.error("Encyption.decrypt: " + e.getMessage(), e);
        throw new TDSEncryptionException("Key is not valid");
    } catch (IllegalBlockSizeException e) {
        log.error("Encyption.decrypt: " + e.getMessage(), e);
        throw new TDSEncryptionException("Block size is not valid");
    } catch (BadPaddingException e) {
        log.error("Encyption.decrypt: " + e.getMessage(), e);
        throw new TDSEncryptionException("Padding is not valid");
    }
}

From source file:TDS.Shared.Web.Encryption.java

/**
 * decrypts a string/* w w w .j a  v  a2  s . com*/
 * 
 * @param stringToDecrypt
 * @return decrypted string
 * @throws TDSEncryptionException
 */
private synchronized String decrypt(String stringToDecrypt) {
    try {

        if (StringUtils.isEmpty(stringToDecrypt)) {
            return "";
        }

        byte[] encryptedBytes = DatatypeConverter.parseBase64Binary(stringToDecrypt);

        byte[] iv = new byte[IV_LENGTH];
        System.arraycopy(encryptedBytes, 0, iv, 0, iv.length);
        _decryptCipher.init(Cipher.DECRYPT_MODE, _secretKey, new IvParameterSpec(iv));
        byte[] cipherBytes = new byte[encryptedBytes.length - IV_LENGTH];
        System.arraycopy(encryptedBytes, IV_LENGTH, cipherBytes, 0, cipherBytes.length);
        byte[] decryptedBytes = _decryptCipher.doFinal(cipherBytes);
        return new String(decryptedBytes, CHARSET_NAME);
    } catch (InvalidAlgorithmParameterException e) {
        _logger.error("Encyption.decrypt: " + e.getMessage(), e);
        throw new TDSEncryptionException("Algorithm is not valid");
    } catch (InvalidKeyException e) {
        _logger.error("Encyption.decrypt: " + e.getMessage(), e);
        throw new TDSEncryptionException("Key is not valid");
    } catch (IllegalBlockSizeException e) {
        _logger.error("Encyption.decrypt: " + e.getMessage(), e);
        throw new TDSEncryptionException("Block size is not valid");
    } catch (BadPaddingException e) {
        _logger.error("Encyption.decrypt: " + e.getMessage(), e);
        throw new TDSEncryptionException("Padding is not valid");
    } catch (UnsupportedEncodingException e) {
        _logger.error("Encyption.decrypt: " + e.getMessage(), e);
        throw new TDSEncryptionException("Encoding is not valid");
    }

}