try {
serviceBytes = service.getBytes("UTF-8");
accountBytes = account.getBytes("UTF-8");
} catch (UnsupportedEncodingException ex) {
throw new PasswordRetrievalException("Unsupported encoding 'UTF-8' specified");
}
//
int[] dataLength = new int[1];
Pointer[] data = new Pointer[1];
//
int status = NativeLibraryManager.Security.SecKeychainFindGenericPassword(
null, serviceBytes.length, serviceBytes,
accountBytes.length, accountBytes,
dataLength, data, null);
if (status != 0) {
throw new PasswordRetrievalException(convertErrorCodeToMessage(status));
}
//
byte[] passwordBytes = data[0].getByteArray(0, dataLength[0]);
//
NativeLibraryManager.Security.SecKeychainItemFreeContent(null, data[0]);
//
try {
return new String(passwordBytes, "UTF-8");
} catch (UnsupportedEncodingException ex) {
throw new PasswordRetrievalException("Unsupported encoding 'UTF-8' specified");
}
}