cryptography

Byte array cryptography in C#

I want to create a nice cryptography using bitwise operators. However I fail to do so. I want it to have bitwise operators using a byte array to encrypt and decrypt my byte array. public class Cryptographer { private byte[] Keys { get; set; } public Cryptographer(string password) { Keys = Encoding.ASCII.GetBytes(pa...

C# - How to calculate ASN.1 DER encoding of a particular hash algorithm?

Given a hash algorithm like SHA1 or SHA256 how would I go about obtaining the ASN.1 DER encoding for it as defined in RFC3447? (see page 42 - link) Below is the desired output. MD5 30 20 30 0c 06 08 2a 86 48 86 f7 0d 02 05 05 00 04 10 SHA-1 30 21 30 09 06 05 2b 0e 03 02 1a 05 00 04 14 SHA-256 30 31 30 0d 06 09 60 86 48 01...

Relation between input and ciphertext length in AES

Having recently started using cryptography in my application, I find myself puzzled by the relationship between the input text length and the ciphertext it results in. Before applying crypto, it was easy to determine the database column size. Now, however, the column size varies slightly. Two questions: Am I correct in assuming this i...

Algorithm to encrypt "numbers" on mobile device so that a wrong password will only reveal wrong numbers but no clue that it is wrong

I am looking for an algorithm to encrypt secret numbers on a mobile device with these properties: Each number has a name associated by the user which is stored in cleartext but may be used to perturb the encryption The number has to be encrypted with the password without revealing a hint about whether a given password is right or wrong...

OneTimePad implementation fails. Maybe a stream problem?

Hi, I had some time and decided to implement a one time pad just for fun and self education. Now I end up with a weird behavior of the data. Its driving me crazy ^^. Would you please help me? Thanks in advance. There is an encrypt method which takes as arguements: an InputStream for the plain text an OutputStreams for the cipher tex...

Do any security experts recommend bcrypt for password storage?

On the surface bcrypt, an 11 year old security algorithm designed for hashing passwords by Niels Provos and David Mazieres, which is based of initialization function used in the NIST approved blowfish algorithm seems almost to good to be true. It is not vulnerable to rainbow tables (since creating them is too expensive) and not even vuln...

Getting random output from Crypto++

Can't figure out why I am getting seemingly random output from the Crypto++ RC2 decoder. The input is always the same, but the output is always different. const char * cipher ("o4hk9p+a3+XlPg3qzrsq5PGhhYsn+7oP9R4j9Yh7hp08iMnNwZQnAUrZj6DWr37A4T+lEBDMo8wFlxliuZvrZ9tOXeaTR8/lUO6fXm6NQpa5P5aQmQLAsmu+eI4gaREvZWdS0LmFxn8+zkbgN/zN23x/sYqIz...

Confused on Miller-Rabin

As an exercise for myself, I'm implementing the Miller-Rabin test. (Working through SICP). I understand Fermat's little theorem and was able to successfully implement that. The part that I'm getting tripped up on in the Miller-Rabin test is this "1 mod n" business. Isn't 1 mod n (n being some random integer) always 1? So I'm confused at ...

How to programmatically create an X.509 certificate in .NET?

I'd like to create a new X.509 certificate in .NET, that meet the hash algorithm and key length requirements that I set. This will be a self-signed certificate. Creating a new certificate may create a new key, or perhaps I'd like to import an existing private key that I have in byte[] form. Does anyone know how to do it? ...

How are my C# and PHP decryption methods different?

I've inherited some C# code and need to port it to PHP. Here it is: string key = "some key"; string strEncrypted = "some encrypted string"; byte[] hashedKey = new MD5CryptoServiceProvider().ComputeHash(UTF8Encoding.UTF8.GetBytes(key)); byte[] strToDecrypt = Convert.FromBase64String(strEncrypted); TripleDESCryptoServiceProvider tripleD...

Generate private RSA key in C#

Hi, I have the values for p, q, n and e and would like to calculate the private key d. How can I do this, could someone give me the example C# code? I am using a BigInteger class to represent the values for p, q, n and e so I assume d will be a BigInteger as well. Thanks, b3n ...

OTP/XOR Cracking two ciphertexts that have the same key

How can I crack two ciphertexts that have used the same key twice? For example, plaintext1 uses the key "abcdefg", and plaintext2 uses the key "abcdefg". I know that ciphertext2 ^ ciphertext1 is equal to plaintext1 ^ plaintext2. And the method to crack plaintext1 ^ plaintext2 is the same method to crack a "book cipher" (also sometimes c...

Is it safe to leave my password-protected PGP secret key available publicly?

My PGP secret keys are always password protected, which means you need to decrypt it using a symmetric key to get access to my private key. I am interested in making my password protected PGP secret key publicly available but I am not entirely sure if I am missing something. Storing my secret key on my computer seems only to be making t...

shorter php cipher than md5?

Hi, For a variety of stupid reasons, the maximum length of a given form variable that we are posting to an external server is 12 characters. I wanted to obscure that value with md5, but obviously with 12 characters that isn't going to work. Is there a cipher with an already-made PHP function which will result in something 12 character...

Strength of hashing algorithms

I've noticed things such as MD5 has been cracked for collisions and is no longer cryptographically secure; use SHA-1 instead. SHA-1 has been cracked for collisions and is no longer cryptographically secure; use SHA-2 instead. From my current understanding, the chance of getting a certain hash h(d) from data d is equal for all hashi...

Is the ASP.NET cryptographic vulnerability work around a BIG LIE?

This question is somewhat of a follow up to How serious is this new ASP.NET security vulnerability and how can I workaround it? So if my question seems to be broken read over this question and its accepted solution first and then take that into the context of my question. Can someone explain why returning the same error page and same st...

hmac message encryption but using our own key

try { // Generate a key for the HMAC-MD5 keyed-hashing algorithm KeyGenerator keyGen = KeyGenerator.getInstance("HmacMD5"); SecretKey key = keyGen.generateKey(); // Generate a key for the HMAC-SHA1 keyed-hashing algorithm keyGen = KeyGenerator.getInstance("HmacSHA1"); key = keyGen.generateKey(); } catch ...

what happens to exe when we sign it?

After signing exe by using VeriSign, if we right click to exe we can see "digital signature" tab which gives information about certificate. Where exactly this information will be stored? I mean how operating system will come to know which certificate is related to which file? Is there anything embed inside exe while signing? How can I wr...

how do convert string to byte[] in C#

How do you get a byte array out of a string in C#? I would like to pass a string to this method. ...

Encrypt string in Python

I need to encrpyt a small string in Python. Is it possible to use a secret key to encrypt the string? Is there a good way to do this and achieve a reasonable encpryption level using only Python libraries? Could you show me how to do this? My knowledge about cryptography is quite basic. : Thank you. ...