/**
* @param path
* @return encoded base64 string String encodeToBase64(String path)
* @throws IOException
* @throws CryptoUnsupportedOperationException
* @throws CryptoTokenException
* @throws CryptoException
*/
public static EncImage encodeToBase64(String path) throws IOException, CryptoException, CryptoTokenException, CryptoUnsupportedOperationException {
EncImage encImage = new EncImage();
FileConnection fileConToRead = null;
InputStream inputStream=null;
try {
fileConToRead = (FileConnection) Connector.open("file://" + path, Connector.READ);
int size = (int) fileConToRead.fileSize();
inputStream = fileConToRead.openInputStream();
byte bytes[] = new byte[size];
inputStream.read(bytes, 0, size);
// If RSA enables
if (Main.isRSAEncrypted) {
CryptoRSA cryptoRSA = new CryptoRSA();
bytes = cryptoRSA.decrypt(bytes);
}
EncodedImage image = EncodedImage.createEncodedImage(bytes, 0, bytes.length);
encImage.setImageHeight(image.getHeight());
encImage.setImageWidth(image.getWidth());
byte encodedBytes[] = Base64.encodeBase64(bytes);
encImage.setEncodesString(new String(encodedBytes));
} finally {
try {
// try to close the FileConnection
fileConToRead.close();
inputStream.close();
} catch (IOException e) {
//finally connection assigns to null
}
// connection set to null
fileConToRead = null;
inputStream=null;
}
return encImage;
}
I hope to share my knowledge with the others in software and networking industry
How to Read RSA Encrypted File to Encoded Image -Java BlackBerry Develpment
Subscribe to:
Post Comments (Atom)
Empowering the Future of API Management: Unveiling the Journey of WSO2 API Platform for Kubernetes (APK) Project and the Anticipated Alpha Release
Introduction In the ever-evolving realm of API management, our journey embarked on the APK project eight months ago, and now, with great a...
-
When we increase timeout value in API Manager we have to set 3 properties. 1) Global timeout defined in synapse.properties (\repository\...
-
No matching resource found error or authentication failure can happen due to few reasons. Here we will discuss about errors can happen d...
-
Address and WSDL endpoints can be suspended if they are detected as failed endpoints. When an endpoint is in in suspended state for a speci...
Excelente post
ReplyDelete