Reputation:
I have two files like this:
Client.java:
public class Client implements Runnable {
//code
public void run() {
//more code
Crypt cls = new Crypt();
cls.decrypt(request,key,type);
//print "val" here.
//more code
}
}
And then the Crypt.java file which is like this:
public class Crypt{
public static byte[] decrypt(byte[] val, byte[] key, int type)
{
//val assigned here
// the following is used to assign it.
val[length - len - 1] ^= key[8 + (((byte)(key[8 + b] + key[8 + a])) & 0xFF)];
return val;
}
}
I need to be able to access the val variable in in the Client.java file again after it has run through the Crypt.java file.
I've tried cls.val
and cls.decrypt.val
but I don't know how to get it working.
Thanks for the help!
Upvotes: 1
Views: 125
Reputation: 11163
Your dycrypt()
method in class Crypt
is a static
member of the Crypt
class. So you don't need to create an instance of Crypt
class in Client
class like -
Crypt cls = new Crypt();
cls.decrypt(request,key,type);
You can just call the decrypt()
method using the class name and store the returns into a byte[]
array -
byte[] vals = Crypt.decrypt(request, key, type);
Then using a for loop/for-each loop you can print the vals
array -
for(byte each : vals){
System.out.println(each);
}
Upvotes: 1
Reputation: 501
Simply assign the return value of dectypt
to a variable and use it.
byte[] res = cls.decrypt(request,key,type);
Upvotes: 0
Reputation: 1015
Since your decrypt()
method returns a value, assign it to a variable when you call it.
byte[] result = cls.decrypt(request, key, type);
and then your result
variable is the value you want, in Client.java
and ready to be used.
Upvotes: 0