Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I don't know C# but I have to do a update to a function that send a key to be encrypted.
I need to send a key with 64 characters, but the function that I have here only accepts 32 characters.
The function that initialize this process is:
Byte[] kkey = System.Text.Encoding.UTF8.GetBytes(sEncKey);
What I have to do for this accept a 64 characteres key?
The code you have included creates an array of type Byte which includes a number of elements matching whatever number of characters you provide in sEncKey.
It is my understanding that you are passing kkey to some function that will perform the encryption, and that this function only accepts a byte array of size 32. If this is correct, then you can't automatically increase the key size to 64 just by sending a longer key - it is the function you will have to change first, not it`s input.
Sound's like you're trying to increase security by using a larger key without replacing the lock first. Get a bigger lock first, then you can use a bigger key.
Also, if you need more help or guidance with this, you will need to provide info about the function, as well as some relevant code.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a method that pseudo-randomly encrypts a byte array. I would like to convert the encrypted byte-array to a C# int (4 bytes), while observing a user-specified lower and upper bound (e.g. give me a number between 1 and 10)
What is the most secure and performant way of achieving this?
You could use System.ByteConverter.ToInt32(arr, start_index).
From your description of the array, the start index would likely be zero.
I am not sure what you mean by upper and lower bound, but if you mean you want a random number, you could use a variety of functions to get a value in between the two numbers. If you have semi-uniform distribution, the modulus function would work nicely. In that case, your random number would simply be lowerBound + (System.ByteConverter.ToInt32(arr, start_index) % (upperBound - lowerBound)).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I have the following code:
void MyBitMaker(int inputNumber)
{
Console.WriteLine(inputNumber << 1);
//TODO
//Bit bitHolder = inputNumber << 1;
//InitMico(ref bitHolder);
}
There is not a type for storing bits in C#. Is there any way to store bits in a variable.
I am programming a micro controller using C#, It uses the bits that are coming from a web service, fetches them and sends them to the controller to open, close, sleep and such things using an interface to change the input data to appropriate bits. My problem is that the micro has just 16 bytes memory in ram and I can not store more than two bytes, the micro should store the history of previous actions (this is extra, maybe, jargon). I have low space and need this small unit. I searched a lot and did not find anything. currently I am using bit operators using a class that I myself have implemented but it's not efficient at all because of using bit operations. I was wondering if someone has faced something that can help me.
The smallest addressable unit is a byte, so use that, or a bool which is still 8 bits, but only has two possible values to be set.
You can't reference a bit, so that would be useless anyway. If you need to address a specific position in a byte, you can pass along the position. Still, you can only change the bit's value by setting the entire byte.
I just want to store bits
Trivial solution: bool array.
If it really needed to store the bits in a compacted form, you can use the BitArray type, which uses an int array internally. You can index it similarly to a normal array:
var myBits = new BitArray(20); // initialize for 20 bits (1 int will be stored internally)
myBits[5] = true; // similar to this: myInt |= 1 << 5;
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I need an algorithm that creates vouchers that is based on an internet kiosk timer. Basically, voucher should have the amount of time allowed encrypted into it. I was thinking of having the amount of time in hex at the start with a few random chars after it then a checksum at the end. However any other ideas are welcome
Use c# builtin libraries for encryption. Since you are the only entity that needs to encrypt/decrypt you can use either a asymetric key(public/private) schema, where you keep both keys private or a symmetric key solution.
Make sure the keys are sufficiently large so that they are not easy to break (at least 256 bits, preferably more).
You don't need to add random chars at the start. You don't need to add checksum at the end. The encryption library should fail to decrypt if the content has been tampered with (accidental character change, but will not stop a very determined attacker). If you want to be extra sure there's been no tampering generate an additional public/private keys and use them to sign the encrypted string.
If you don't care that users can see your voucher string, you can just put it in plain text and just use the libraries to sign it.
So all you need is to have a class that is serializable and contains all the fields of your voucher. Get the serialized string and pass it through the encryption/signing routines. When you get it backs use the same routines to make sure the string is authentic then deserialize it and you have your data.
The most important thing is to use the libraries correctly (follow the tutorials, instructions) and you keep your keys safe.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have an input byte array which is huge in size ( > 8000 bytes). I need to store this byte array in DB, and fetch later for further operation.
The problem is, this byte array column is unique. Assume that if I need to retrieve the entire table information on this byte array column. It becomes extremely costly operation when it comes to byte comparison. So thought of storing the Hash Value of this byte array just to make the comparison operation easier.
Just wanted to know if hash value which is generated from the byte array will be unique OR is there any other way to achieve this.
If the size (in bytes) of the hash is smaller than 8000, this is not possible. After all, there are 256 ^ 8000 possible inputs, so there must be at least that many possible outputs if the hash function needs to be unique.
As the default C# hashcode returns an int, which (depending on your architecture) is 32 or 64 bits (so 4 or 8 bytes), this is not even close to be possible with the default hash function. (Of course, you could write your own hash function, but that's quite pointless.)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I`m using C# and I need to read something after EOF. Is it possible by using C#? How?
Thanks.
You cant. EOF means end of file, there's nothing actually in the file after that.
You may as well ask how you can get ten gallons of oil from a four-gallon drum. Once it's empty, there's no more to be had.
Since you're talking C# hence Windows (and based on your comment and data located behind the end of file pointer), it's possible that they may be referring to "DOS mode" text files, which are (or used to be, I haven't investigated recently) terminated by the CTRL-Z character.
From the earliest days of the PC revolution, where CP/M used integral numbers of disk blocks to store a file and only stored the number of disk blocks rather than the number of bytes, CTRL-Z was used to indicate end of file if the file wasn't an exact multiple of the disk block size.
If that's the case, it's probably best just to open the file as a binary file, then read up to the first CTRL-Z character (code point 26) - everything beyond that could be considered data beyond EOF if it's truly a text file of that format.