/**
* @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...
-
First you have to download the font file "filename.ttf" to you machine. Then you need some permissions to add those files to fold...
-
Remove current installation of Nginx sudo apt-get purge nginx nginx-common nginx-full Install Nginx sudo apt-get install nginx Edit c...
-
When we calling an API, we request for an oauth token which we send with each API call. The reason for introduce OpenID on top of oauth 2...
Excelente post
ReplyDelete