Padding is invalid and cannot be removed in C# licensing method
in my project I'm Doing a licensing method where after the user enters the
license key his product will be activated. Im using the following code but
I'm getting an exception thrown saying "Padding is invalid and cannot be
removed". The following is my code
public void ValidateProductKey()
{
RSACryptoServiceProvider _cryptoService = new
RSACryptoServiceProvider();
string productKey = "G7MA4Z5VR5R3LG001AS1N5HA3YHX05";
byte[] keyBytes =
Base32Converter.FromBase32String(productKey);
//Base32Converter is my customized method which returns byte
of values;
byte[] signBytes = new byte[2];
byte[] hiddenBytes = new byte[16];
using (MemoryStream stream = new MemoryStream(keyBytes))
{
stream.Read(hiddenBytes, 0, 8);
stream.Read(signBytes, 0, 2);
stream.Read(hiddenBytes, 8, hiddenBytes.Length - 8);
keyBytes = stream.ToArray();
}
byte[] sign = _cryptoService.SignData(signBytes, new
SHA1CryptoServiceProvider());
byte[] rkey = new byte[32];
byte[] rjiv = new byte[16];
Array.Copy(sign, rkey, 32);
Array.Copy(sign, 32, rjiv, 0, 16);
SymmetricAlgorithm algorithm = new RijndaelManaged();
try
{
hiddenData = algorithm.CreateDecryptor(rkey,
rjiv).TransformFinalBlock(hiddenBytes,0,hiddenBytes.Length);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
When reaching the "hiddenData" variable I get an exception thrown as
"Padding is invalid and cannot be removed". Any help would be really
appreciated.
Bollens
Thursday, 3 October 2013
Wednesday, 2 October 2013
Collection and toArray in Scala
Collection and toArray in Scala
Java code:
Collection<MethodInfo> items = getItems();
MethodInfo[] itemsArray = methods.toArray(new MethodInfo[methods.size()]);
I wonder, what would be the equivalent code in Scala?
val items: Seq[MethodInfo] = getItems
val itemsArray: Array[MethodInfo] = ???
Java code:
Collection<MethodInfo> items = getItems();
MethodInfo[] itemsArray = methods.toArray(new MethodInfo[methods.size()]);
I wonder, what would be the equivalent code in Scala?
val items: Seq[MethodInfo] = getItems
val itemsArray: Array[MethodInfo] = ???
Very basic Java nested for loop issue
Very basic Java nested for loop issue
I'm having a hard time trying to get this code to start at 5 spaces and
reduce to 0 spaces, subtracting a space every line.
public class Prob3 {
public static void main(String[]args) {
for (int x=1; x<=5; x++)
{
for (int y=5; y>=1; y--)
{
System.out.print(" ");
}
System.out.println(x);
}
}
}
Current output is (should be 5 spaces):
5
4
3
2
1
I'm happy with the progress so far but I need to get something closer to
this:
1
2
3
4
5
I feel like I'm pretty close
Edit got it.
public class Prob3 {
public static void main(String[]args) {
for (int x=1; x<=5; x++)
{
for (int y=5; y>=x; y--)
{
System.out.print(" ");
}
System.out.println(x);
}
}
}
I'm having a hard time trying to get this code to start at 5 spaces and
reduce to 0 spaces, subtracting a space every line.
public class Prob3 {
public static void main(String[]args) {
for (int x=1; x<=5; x++)
{
for (int y=5; y>=1; y--)
{
System.out.print(" ");
}
System.out.println(x);
}
}
}
Current output is (should be 5 spaces):
5
4
3
2
1
I'm happy with the progress so far but I need to get something closer to
this:
1
2
3
4
5
I feel like I'm pretty close
Edit got it.
public class Prob3 {
public static void main(String[]args) {
for (int x=1; x<=5; x++)
{
for (int y=5; y>=x; y--)
{
System.out.print(" ");
}
System.out.println(x);
}
}
}
too few arguments in function call error
too few arguments in function call error
Doing an assignment to calculate the area and volume of different shapes.
Stuck is an understatement. Get an error claiming 'showMenu': function
does not take 0 arguments & a also a too few arguments in function call
error. Any pointers on how to fix this?
#include <iostream>
#include <iomanip>
using namespace std;
//Functions
void showMenu(int &);
double area (double, double);
double area (double);
double volume (double, double, double);
double volume (double);
const double PI = 3.14;
int main()
{
int choice;
double area, volume, length, width, radius, height;
const double PI = 3.14;
do
{
showMenu();
cin >> choice;
if (choice < 1 || choice > 5 )
{
cout << "Please select a valid choice of 1-5: " << endl;
cin >> choice;
}
else if (choice == 1)
{
double tarea(area);
cout << "Enter the length: ";
cin >> length;
cout << "Enter the width: ";
cin >> width;
cout << "The area of the rectangle is: " << tarea << endl;
}
else if (choice == 2)
{
double tarea(area);
cout << "Enter the radius: ";
cin >> radius;
cout << "The area of the circle is: " << tarea << endl;
}
else if (choice == 3)
{
double tvolume (volume);
cout << "Enter the length: ";
cin >> length;
cout << "Enter the width: ";
cin >> width;
cout << "Enter the height: ";
cin >> height;
cout << "The volume for a box is: " << tvolume << endl;
}
else if (choice == 4)
{
double tvolume (volume);
cout << "Enter the radius: ";
cin >> radius;
cout << "The volume of a sphere is: " << endl;
}
}
while (choice != 5);
return 0;
}
void ShowMenu(int &choice)
{
cout << "1. Calculate the area of a rectangle";
cout << "2. Calculate the area of a circle";
cout << "3. Calculate the volume for a box";
cout << "4. Calculate the volume of a sphere";
cout << "5. Quit";
}
double area (double length, double width)
{
double tarea = length * width;
return tarea;
}
double area (double radius)
{
double tarea = PI * (radius * radius);
return tarea;
}
double volume (double length, double width, double height)
{
double tvolume = length * width * height;
return tvolume;
}
double volume (double radius)
{
double tvolume = (4/3) * PI * (radius * radius * radius);
return tvolume;
}
Doing an assignment to calculate the area and volume of different shapes.
Stuck is an understatement. Get an error claiming 'showMenu': function
does not take 0 arguments & a also a too few arguments in function call
error. Any pointers on how to fix this?
#include <iostream>
#include <iomanip>
using namespace std;
//Functions
void showMenu(int &);
double area (double, double);
double area (double);
double volume (double, double, double);
double volume (double);
const double PI = 3.14;
int main()
{
int choice;
double area, volume, length, width, radius, height;
const double PI = 3.14;
do
{
showMenu();
cin >> choice;
if (choice < 1 || choice > 5 )
{
cout << "Please select a valid choice of 1-5: " << endl;
cin >> choice;
}
else if (choice == 1)
{
double tarea(area);
cout << "Enter the length: ";
cin >> length;
cout << "Enter the width: ";
cin >> width;
cout << "The area of the rectangle is: " << tarea << endl;
}
else if (choice == 2)
{
double tarea(area);
cout << "Enter the radius: ";
cin >> radius;
cout << "The area of the circle is: " << tarea << endl;
}
else if (choice == 3)
{
double tvolume (volume);
cout << "Enter the length: ";
cin >> length;
cout << "Enter the width: ";
cin >> width;
cout << "Enter the height: ";
cin >> height;
cout << "The volume for a box is: " << tvolume << endl;
}
else if (choice == 4)
{
double tvolume (volume);
cout << "Enter the radius: ";
cin >> radius;
cout << "The volume of a sphere is: " << endl;
}
}
while (choice != 5);
return 0;
}
void ShowMenu(int &choice)
{
cout << "1. Calculate the area of a rectangle";
cout << "2. Calculate the area of a circle";
cout << "3. Calculate the volume for a box";
cout << "4. Calculate the volume of a sphere";
cout << "5. Quit";
}
double area (double length, double width)
{
double tarea = length * width;
return tarea;
}
double area (double radius)
{
double tarea = PI * (radius * radius);
return tarea;
}
double volume (double length, double width, double height)
{
double tvolume = length * width * height;
return tvolume;
}
double volume (double radius)
{
double tvolume = (4/3) * PI * (radius * radius * radius);
return tvolume;
}
How to run remote ssh session from Jenkins with sudo rights?
How to run remote ssh session from Jenkins with sudo rights?
Using 'Execute shell script on remote host using ssh' option and need sudo
rights on remote server to change permissions and remove protected files.
How to run session with this rights?
Getting message
sudo: sorry, you must have a tty to run sudo
when trying to run sudo command.
Using 'Execute shell script on remote host using ssh' option and need sudo
rights on remote server to change permissions and remove protected files.
How to run session with this rights?
Getting message
sudo: sorry, you must have a tty to run sudo
when trying to run sudo command.
Tuesday, 1 October 2013
Convert MySQL query from a nested select to an inner join
Convert MySQL query from a nested select to an inner join
I have a nested select statement that works as it should, the only problem
is that it takes too long to run. I converted one of my other queries to
an inner join and it is much much faster. I'm trying to convert this query
to an inner join.
Current working query:
select date(datetime), req_origin, count( distinct session_id)
from LOG L1
where((datetime >= str_to_date('2013-01-01 00:00:00','%Y-%m-%d %H:%i:%s'))
and (datetime < str_to_date('2013-01-05 00:00:00','%Y-%m-%d %H:%i:%s'))
and code_subcode in ('1001111','1001112','1001113','1001114'))
and ((
select count(*) from LOG L2 where L2.session_id = L1.session_id and
date(L2.datetime)
= date(L1.datetime)
and code_subcode in ('1001111','1001112','1001113','1001114')
) = 4)
group by date(datetime),req_origin order by date(datetime),req_origin;
This is what I've got for an inner join but it isn't working properly. It
only returns data when check for 1 matching code. When I query for 4
matching codes the query doesn't return anything.
select date(l1.datetime), l1.req_origin, count(distinct l1.session_id)
from LOG l1
INNER JOIN LOG l2 on l2.SESSION_ID = l1.SESSION_ID
where((l1.datetime >= str_to_date('2013-01-01 00:00:00','%Y-%m-%d %H:%i:%s'))
and (l1.datetime < str_to_date('2013-01-05 00:00:00','%Y-%m-%d %H:%i:%s'))
and l1.code_subcode in ('1001111','1001112','1001113','1001114')
and l2.code_subcode in ('1001111','1001112','1001113','1001114') = 4)
group by date(l1.datetime), l1.req_origin order by date(l1.datetime),
l1.req_origin;
Thanks in advance for any help!
I have a nested select statement that works as it should, the only problem
is that it takes too long to run. I converted one of my other queries to
an inner join and it is much much faster. I'm trying to convert this query
to an inner join.
Current working query:
select date(datetime), req_origin, count( distinct session_id)
from LOG L1
where((datetime >= str_to_date('2013-01-01 00:00:00','%Y-%m-%d %H:%i:%s'))
and (datetime < str_to_date('2013-01-05 00:00:00','%Y-%m-%d %H:%i:%s'))
and code_subcode in ('1001111','1001112','1001113','1001114'))
and ((
select count(*) from LOG L2 where L2.session_id = L1.session_id and
date(L2.datetime)
= date(L1.datetime)
and code_subcode in ('1001111','1001112','1001113','1001114')
) = 4)
group by date(datetime),req_origin order by date(datetime),req_origin;
This is what I've got for an inner join but it isn't working properly. It
only returns data when check for 1 matching code. When I query for 4
matching codes the query doesn't return anything.
select date(l1.datetime), l1.req_origin, count(distinct l1.session_id)
from LOG l1
INNER JOIN LOG l2 on l2.SESSION_ID = l1.SESSION_ID
where((l1.datetime >= str_to_date('2013-01-01 00:00:00','%Y-%m-%d %H:%i:%s'))
and (l1.datetime < str_to_date('2013-01-05 00:00:00','%Y-%m-%d %H:%i:%s'))
and l1.code_subcode in ('1001111','1001112','1001113','1001114')
and l2.code_subcode in ('1001111','1001112','1001113','1001114') = 4)
group by date(l1.datetime), l1.req_origin order by date(l1.datetime),
l1.req_origin;
Thanks in advance for any help!
Cannot figure out an Excel formula
Cannot figure out an Excel formula
I have tried every answer I could find on the boards and I could not get
this to work....
I want to check for a cell match in another column on a different
worksheet and if it finds one it will copy the cells from the same row
from four specific columns to four specific columns.
Here is the logic: If Sheet1 B2 is equal to Sheet2 Column K Any Row in
then return Sheet2 Column A,B,C,E from the same row of the match to Sheet1
I2,J2,K2,L2
Thank you so very much for any guidence you can give me! ~Brian
I have tried every answer I could find on the boards and I could not get
this to work....
I want to check for a cell match in another column on a different
worksheet and if it finds one it will copy the cells from the same row
from four specific columns to four specific columns.
Here is the logic: If Sheet1 B2 is equal to Sheet2 Column K Any Row in
then return Sheet2 Column A,B,C,E from the same row of the match to Sheet1
I2,J2,K2,L2
Thank you so very much for any guidence you can give me! ~Brian
Subscribe to:
Comments (Atom)