Please don't mark it as duplicate.   I am using Blowfish Algorithm to Encrypt and Decrypt a Contents in a File. The problem is the output characters of encrypted file having too much of special characters   SPECIAL CHARACTERS (Encrypted text) :- Ž81‡Ç¬ú²±DN¢HÜ4ºÜºT÷.Ê+ŠÀ  after that i had converted the special characters to hex it gives the value as  8E383187C7ACFAB214B113444EA248DC34BADCBA54F7032ECA2B8AC03C6B95C67D2F46F586E4CD86  if i tried to convert this to string i cant get the same encrypted text  Following java code for converting hex to string  package bytearray;  import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import javax.xml.bind.DatatypeConverter;    public class ByteArray {       public static byte[] toByteArray(String s) {         return DatatypeConverter.parseHexBinary(s);     }      public static void main(String[] args) throws IOException {         String balaji  ="8E383187C7ACFAB214B113444EA248DC34BADCBA54F7032ECA2B8AC03C6B95C67D2F46F586E4CD86";          byte[] pri = toByteArray(balaji);         String value = new String(pri);         System.out.println(value);       }  }   Please help us how to convert the hex to string.  Expected Output :-  Ž81‡Ç¬ú²±DN¢HÜ4ºÜºT÷.Ê+ŠÀ  Obtained output:- �81�Ǭ���DN�H�4�ܺT�.�+��
2136
I am looking for a way to convert a long string (from a dump), that represents hex values into a byte array.  I couldn't have phrased it better than the person that posted .  But to keep it original, I'll phrase it my own way: suppose I have a string "00A0BF" that I would like interpreted as the  byte[] {0x00,0xA0,0xBf}   what should I do?  I am a Java novice and ended up using BigInteger and watching out for leading hex zeros. But I think it is ugly and I am sure I am missing something simple.
68490
In JavaScript:  encodeURIComponent("©√") == "%C2%A9%E2%88%9A"   Is there an equivalent for C# applications? For escaping HTML characters I used:  txtOut.Text = Regex.Replace(txtIn.Text, @"[\u0080-\uFFFF]",     m =&gt; @"&amp;#" + ((int)m.Value[0]).ToString() + ";");   But I'm not sure how to convert the match to the correct hexadecimal format that JS uses. For example this code:  txtOut.Text = Regex.Replace(txtIn.Text, @"[\u0080-\uFFFF]",     m =&gt; @"%" + String.Format("{0:x}", ((int)m.Value[0])));   Returns "%a9%221a" for "©√" instead of "%C2%A9%E2%88%9A". It looks like I need to split the string up into bytes or something.  Edit: This is for a windows app, the only items available in System.Web are: AspNetHostingPermission, AspNetHostingPermissionAttribute, and AspNetHostingPermissionLevel.
34188
I'm attempting to get a better understanding of cryptography and have run into some questions about bcrypt.   Bcrypt relies on the blowfish cipher, which is a reversible method of encryption. But bcrypt is not reversible. How is that possible? Or am I mistaken? What does bcrypt do on top of blowfish to make it irreversible? Why does bcrypt use blowfish instead of twofish or threefish?
85743
I am working on a project that uses a CSV file supplied by the client to populate a database. The client is to create the spreadsheet, then save it as a CSV to be uploaded, which is then parsed into a database.  The problem is, whenever the client saves the excel spreadsheet as an MS-DOS .csv file, many of the special characters get converted to question marks "?" (symbols such as ' " / ). However, if we then open the CSV file and manually replace each ? with the right character it works fine.  The problem is that the data file is HUGE, and we can't reasonably do this, so I was hoping there was a way to save it. We have tried exporting as Unicode and ASCII to no avail. We have also tried uploading to google docs, and re-saving, however, it also breaks those characters.
13844
In Java, there is no such thing as an unsigned byte.  Working with some low level code, occasionally you need to work with bytes that have unsigned values greater than 128, which causes Java to interpret them as a negative number due to the MSB being used for sign.  What's a good way to work around this? (Saying don't use Java is not an option)
112589
I've just realized I have a file on my system; it lists normally:  $ ls -la TΕSТER.txt  -rw-r--r-- 1 user user 8 2013-04-11 18:07 TΕSТER.txt $ cat TΕSТER.txt  testing   ... yet, it crashes a piece of software with a UTF-8/Unicode related error. I was really puzzled, since I couldn't tell why such a file is a problem; and finally I remembered to check the output of ls with hexdump:  $ ls TΕSТER.txt  TΕSТER.txt $ ls TΕSТER.txt | hexdump -C 00000000  54 ce 95 53 d0 a2 45 52  2e 74 78 74 0a           |T..S..ER.txt.| 0000000d   ... Well, obviously there are some bytes in between/instead of some letters, so I guess it is a Unicode encoding problem. And I can try to echo the bytes back to see what is printed:  $ echo -e "\x54\xCE\x95\x53\xD0\xA2\x45\x52\x2E\x74\x78\x74" TΕSТER.txt   ... but I still cannot tell which - if any - Unicode characters these are.   So is there a command line tool, which I can to inspect a string on the terminal, and get Unicode information about it's characters?
39676
How do I convert a string to a byte[] in .NET (C#) without manually specifying a specific encoding?  I'm going to encrypt the string. I can encrypt it without converting, but I'd still like to know why encoding comes to play here.  Also, why should encoding even be taken into consideration? Can't I simply get what bytes the string has been stored in? Why is there a dependency on character encodings?
78736
I had given an cipher text (of JSON string), an IV and a key. I tried decrypting using 's method:      decryptWithManagedIV(algorithmName, privateKey, IVAndCipherText)     //Sample code   Blob key = Blob.valueOf(decryptionKey);   Blob encryptedDatafor = EncodingUtil.base64Decode(bodystring);   Blob decryptedData = Crypto.decryptwithManagedIV('AES128', key, encryptedDatafor);    cipher = decryptedData.toString();   System.debug('Encrypted BodyString: ' +cipher);   and I was able to decrypt the cipher successfully. But when I use the provided IV with the following method:      decrypt(algorithmName, privateKey, initializationVector, cipherText)    //Sample code  Blob exampleIV = Blob.valueOf('HSDlUkhrmfEo7SgM'); //provided IV   Blob key = Blob.valueOf(decryptionKey);  Blob encryptedDatafor = EncodingUtil.base64Decode(bodystring);  Blob decryptedDataIV = Crypto.decrypt('AES128', key, exampleIV, encryptedDatafor);   cipher = EncodingUtil.base64Encode(decryptedDataIV );  System.debug('Encrypted BodyString: ' +cipher);   I get some string which looks like, it is still in the encrypted form (different from the encrypted string I have passed).   Update:  I have tried the below code-snippet based on the suggestion from @identigral, but I am still unable to decrypt the cipher using the IV:  Blob exampleIV = Blob.valueOf('HSDlUkhrmfEo7SgM'); //provided IV  Blob key = Blob.valueOf(decryptionKey); Blob encryptedDatafor = EncodingUtil.base64Decode(bodystring);  String encodedCipherTextAndIV = EncodingUtil.convertToHex(encryptedDatafor); String encodedCipherText = encodedCipherTextAndIV.substring(32); String finCipher = encodedCipherText.difference(encodedCipherTextAndIV); Blob ciphertext = EncodingUtil.convertFromHex(finCipher);   Blob decryptedDataIV = Crypto.decrypt('AES128', key, exampleIV, ciphertext);  decryptStg = EncodingUtil.base64Encode(decryptedDataIV ); System.debug('Decrypted BodyString: ' +decryptStg);
69570
I'm testing an implementation of Bitcoin, which uses the curve Secp256k1 for ECDSA, and I want to see how it handles the point at infinity ($0$) if present in a signature. For example, r could be the x coordinate of the encoding of the point at infinity.   How is the $0$ encoded? Can it be encoded?  I found that bouncycastle prefixes the encoding of 0 with 0x00, and has some other defined prefixes (ECCurve.decodePoint()) but I don't known how this information applies (or even if it does apply to) to the encoding of $(r,s)$. This info seems to be in the X9.62 standard.
43645
Suppose you want to generate a password using ASCII  characters ($128$ characters.)How many ways can you create a password of 10 characters long that has at least one lowercase letter (a-z) and at least one number ($0-9$)?  ** MY ANSWER: $26*10*(128)^{10}$**  I don't understand why this is wrong? Can anybody help? Thanks!
115825
Is there any pair of 128-bit strings M and K such that AES$_K$(M) = M?  If yes, how do I go about (efficiently) finding such a pair?
79644
So I'm checking the md5 hash of my files with this as my output:  657cf4512a77bf47c39a0482be8e41e0  ./dupes2.txt 657cf4512a77bf47c39a0482be8e41e0  ./dupes.txt 8d60a927ce0f411ec94ac26a4785f749  ./derpina.txt 15f63928b8a1d5337137c38b5d66eed3  ./foo.txt 8d60a927ce0f411ec94ac26a4785f749  ./derp.txt   However, after running find . -type f -exec md5sum '{}' ';' | uniq -w 33 to find the unique hashes I get this:  657cf4512a77bf47c39a0482be8e41e0  ./dupes2.txt 8d60a927ce0f411ec94ac26a4785f749  ./derpina.txt 15f63928b8a1d5337137c38b5d66eed3  ./foo.txt 8d60a927ce0f411ec94ac26a4785f749  ./derp.txt   From my understanding, only one of either derpina.txt or derp.txt should be showing up since their hashes are the same. Am I missing something? Can anyone enlighten me as to why it outputs like this?
91060
When I do hexdump filename.txt I get the following as output:  00000000 ac5a 5afb c08d 5d15 26d0 2491 e8c9 8917 00000010    When I do &lt;?= bin2hex(file_get_contents('filename.txt')); ?&gt; I get this:  5aacfb5a8dc0155dd0269124c9e81789   So why is hexdump suggesting the contents should be ac5a5afbc08d5d1526d02491e8c98917 when PHP is suggesting they ought to be 5aacfb5a8dc0155dd0269124c9e81789? Am I just not interpreting the output of hexdump correctly?
49432
I'm working in a C++ unmanaged project.  I need to know how can I take a string like this "some data to encrypt" and get a byte[] array which I'm gonna use as the source for Encrypt.  In C# I do    for (int i = 0; i &lt; text.Length; i++)     buffer[i] = (byte)text[i];   What I need to know is how to do the same but using unmanaged C++.  Thanks!
92411
If I have an encoding function  $f(x)$ that maps a message $m$ to a point $P$ on a suitable Elliptic Curve $E$ . If I have the public key $Q$ of my recepient then I can encrypt the message as follows:  Choosing a random number $k &lt; n -1 $ where $n$ is the order of the curve E .  Calculating $C = [k] G $ where $G$ is the generator point of the curve E   Calculating $R = [k]Q $ where $Q$ is the recipient's public key   Now the message is encrypted by adding $P$ to $R$ to get          $C_e$ $( = R + P)$ which is sent along with $C$ to the recepient.  DECRYPTION:  Now for the recepient to decrypt my message they compute $R = [privatekey] C $ (where $C = [k]G $) and simply subtract $R$ from $C_e$ to get the encoded point $P$ back which is then decoded by an inverse function $f^{-1}(x)$ to recover $m$.  Now , two problems arise : If the attacker knows the plaintext (suppose if I follow a particular format of data while sending messages ) he could encode his guessed plaintext and subtract it from $C_e$ to recover $ R $ back ! . If I used that same $ R  $ to encrypt further "blocks" of my message then the security of the later parts of my message has been breached!   I realize that doing  something like a scalar multiplication over and over again for every block of data, would be a huge drawback in efficiency and speed.   Is there any way to compute a different $ R $ for every block of data, without using much resources and that too quickly ?   Does reusing the same $R$ for another message break security ?  NOTE: This question is for educational purposes only. It's for the sake of expanding my knowledge on Crypto.
20332
i just made a test, to see how much data i can put in a string before i reach the the heapsize limit and i get an unexpected behaviour   string  csvFile = '"XXXXXXX","XXPX XXRXXXX","XXPX BP","XLXXXXR","XXXXVXXX PRXXXDXXXX","XXPX XXXXVXXX","XDRXXXDXX LXGXLX","XXXXRX XXLX","LXXXX XX","DXXX XXXZXX XXXXVXXX","DXXX XXXX XXXXVXXX","XXDXXX BP","XXDXXX XXXXXLX","PXRXXXX XVX","DXXXXXXXZXXXX","XXXX XXRXXXXRX","XXGXXXX XXRXXXXRX","DXXX DX XXXXXXX","LXXGX DX XXXXXXX","PXD","XXXXX XXXXRXXXXXLX","XXXX RXXXPXXX","XXDXRXZZX RXXXPXXX","PRXVXXXXX RXXXPXXX","XXXXXX RXXXPXXX","XXP RXXXPXXX","XXXXRX XXLXXXXX 1","XXXXRX XXLXXXXX 2","XXXXRX XXX","XXDXRXZZX XXXXL","XXDXRXZZX XXRXXXXRX","XXXXXX XXRXXXXRX","PRXVXXXXX XXRXXXXRX","XXP XXRXXXXRX","XXXXX XLXXXXX","XXDXXX PRXXXXX","DXXX XXXXXZXXXX","XXPX DXXXXXXXX","XHXXVX XXXXXRX","DXXX XXXXXXXXX XXXXXRX","DXXX XXXDXXZX XXXXXRX","XXPXRXX XXXXLX","XXPXRXX RXXXDXX XXXXDXXX","PRXXXXXXXXXXXXXXZXXXX PRXXXXXXXXXX","DXXX PRXXXXXXXXXXXXXXZXXXX PRXXXXXXXXXX"';  string  csvFile2='',csvFile3; system.debug(limits.getLimitHeapSize()); system.debug(limits.getHeapSize()); for(integer i=0;i&lt;3618;i++){ csvFile2+='\n'+csvFile; }   system.debug(1.0*limits.getHeapSize()); system.debug((1.0*limits.getHeapSize())/limits.getLimitHeapSize()*100);   with 3618 iteraction i get    Heap size 3001245.0 Which correspond to ~50% of the heap size limit in the Synchronous context   but if i go to 3619 iteractions in the for, i get the error "Apex heap size too large: 6001368".... which surprise me a lot...   I'm not getting out why this behaviour is occurring. Do you have any similar experience? There is a reason for this?  Seems more about limits on strings, in effect the string csvFile2 overcome 3M characters... but i dont know
10266
I have embedded a Python interpreter in a C program.  Suppose the C program reads some bytes from a file into a char array and learns (somehow) that the bytes represent text with a certain encoding (e.g., ISO 8859-1, Windows-1252, or UTF-8).  How do I decode the contents of this char array into a Python string?  The Python string should in general be of type unicode—for instance, a 0x93 in Windows-1252 encoded input becomes a u'\u0201c'.  I have attempted to use PyString_Decode, but it always fails when there are non-ASCII characters in the string.  Here is an example that fails:  #include &lt;Python.h&gt; #include &lt;stdio.h&gt;  int main(int argc, char *argv[]) {      char c_string[] = { (char)0x93, 0 };      PyObject *py_string;       Py_Initialize();       py_string = PyString_Decode(c_string, 1, "windows_1252", "replace");      if (!py_string) {           PyErr_Print();           return 1;      }      return 0; }   The error message is UnicodeEncodeError: 'ascii' codec can't encode character u'\u201c' in position 0: ordinal not in range(128), which indicates that the ascii encoding is used even though we specify windows_1252 in the call to PyString_Decode.  The following code works around the problem by using PyString_FromString to create a Python string of the undecoded bytes, then calling its decode method:  #include &lt;Python.h&gt; #include &lt;stdio.h&gt;  int main(int argc, char *argv[]) {      char c_string[] = { (char)0x93, 0 };      PyObject *raw, *decoded;       Py_Initialize();       raw = PyString_FromString(c_string);      printf("Undecoded: ");      PyObject_Print(raw, stdout, 0);      printf("\n");      decoded = PyObject_CallMethod(raw, "decode", "s", "windows_1252");      Py_DECREF(raw);      printf("Decoded: ");      PyObject_Print(decoded, stdout, 0);      printf("\n");      return 0; }