dialogCreateAlert('Please, select a document to be processed!');
$file_list = array('form1.docx', 'form2.docx', 'form3.docx');
$droid->dialogSetItems($file_list);
$droid->dialogShow();
$result = '';
$result = $droid->dialogGetResponse();
$data_input = '';
$data_input = $file_list[$result['result']->item];
$url = 'http://localhost/document/store.php' . '?' . 'file=' . $data_input;
$droid->makeToast('url: ' . $url);
//display list of actions
$droid->dialogCreateAlert('Please, choose an action to be performed!');
$action_list = array('View', 'Sign', 'Encrypt', 'Cancel');
$droid->dialogSetItems($action_list);
$droid->dialogShow();
$result = '';
$result = $droid->dialogGetResponse();
$data_input = '';
$data_input = $action_list[$result['result']->item];
$url = $url . '&action='. $data_input;
$droid->makeToast('url: ' . $url);
//perform selected action
if ($data_input == 'View')
{
$droid->dialogDismiss();
$droid->makeToast('Thank you for using CryptScript!');
}
elseif ($data_input == 'Sign')
{
$pkcs12_password = $droid->dialogGetPassword('Private key protection', 'Please, enter the password:');
$result = '';
$result['result'] = cryptscript_sign($data_input, $pkcs12_password['result']);
$droid->dialogCreateAlert('The signature value is: ' . $result['result']);
$droid->dialogSetNegativeButtonText('Done');
$droid->dialogShow();
$result = '';
$result = $droid->dialogGetResponse();
$data_input = '';
$data_input = $result['result']->which;
$droid->makeToast('Thank you for using CryptScript!');
}
elseif ($data_input == 'Encrypt')
{
$droid->dialogDismiss();
$droid->makeToast('Thank you for using CryptScript!');
}
elseif ($data_input == 'Cancel')
{
$droid->dialogDismiss();
$droid->makeToast('Thank you for using CryptScript!');
}
else
{
$droid->dialogDismiss();
$droid->makeToast('Thank you for using CryptScript!');
}
//perform Sign action
function cryptscript_sign($data_input, $pkcs12_password)
{
$message = '';
$pkcs12_file = '';
$pkcs12_content = '';
$pkcs12_file_path = '/mnt/sdcard/sl4a/scripts/test-end.p12';
$pkcs12_password = $pkcs12_password;;
$data_input = $data_input;
$signature_algorithm = OPENSSL_ALGO_SHA1;
$signature_value = '';
if ($pkcs12_file_path != '')
{
$file_pointer = fopen($pkcs12_file_path, 'r');
}
else
{
echo '
ERROR: The file path is not set properly!';
$message = $message . ' ERROR: The file path is not set properly!';
}
if ($file_pointer != FALSE)
{
$pkcs12_file = fread($file_pointer , 8192);
fclose($file_pointer);
}
else
{
echo '
ERROR: The file can not be found!';
$message = $message . ' ERROR: The file can not be found!';
}
if ($pkcs12_file != FALSE)
{
$openssl_pkcs12_read_result = '';
$openssl_pkcs12_read_result = openssl_pkcs12_read($pkcs12_file, $pkcs12_content, $pkcs12_password);
}
else
{
echo '
ERROR: The file can not be accessed!';
$message = $message . ' ERROR: The file can not be accessed!';
}
if ($openssl_pkcs12_read_result != FALSE)
{
$openssl_sign_result = '';
$openssl_sign_result = openssl_sign($data_input, $signature_value, $pkcs12_content['pkey'], $signature_algorithm);
$signature_value = base64_encode($signature_value);
}
else
{
echo '
ERROR: The content of file can not be processed (not valid file content, wrong password etc.)!';
$message = $message . ' ERROR: The content of file can not be processed (not valid file content, wrong password etc.)!';
}
if ($openssl_sign_result != FALSE)
{
echo '
OK: The computed signature value is: ' . $signature_value;
return $signature_value;
}
else
{
echo '
ERROR: The signature can not be created (not supported algorithm etc.)!';
$message = $message . ' ERROR: The signature can not be created (not supported algorithm etc.)!';
return $message;
}
}
?>