cryptography

Calculate hash when writing to stream

孤人 提交于 2020-01-31 04:31:25
问题 I am currently creating an encrypted file format that needs to be signed. For this I need to calculate the hash code of the content I have written to a stream. In the .net framework there is numerous hash algorithms that can be used, and it works fine, but it requires me to process the stream three times. byte[] content = new byte[] { 0, 1, 2, 3, 4, 5, 6 }; using (Stream fileStream = File.Open("myfile.bin", FileMode.Create)) { //Write content fileStream.Write(content, 0, content.Length); }

Why does this encrypted string have funny characters in it? It isn't readable?

和自甴很熟 提交于 2020-01-30 09:50:13
问题 I'm converting the encrypted text using UTF8, yet the resulting string has funny characters that I can't read and not sure if I can send this text to the browser. string message = "hello world"; var rsa = new RSACryptoServiceProvider(2048); var c = new UTF8Encoding(); byte[] dataToEncrypt = c.GetBytes(message); byte[] encryptedData = rsa.Encrypt(dataToEncrypt, false); string output = c.GetString(encryptedData); Console.WriteLine(output); Console.ReadLine(); When I run the above, I get the

How could one design a secure and “self-destructing” email?

回眸只為那壹抹淺笑 提交于 2020-01-29 17:52:22
问题 As most of you know, email is very insecure. Even with a SSL-secured connection between the client and the server that sends an email, the message itself will be in plaintext while it hops around nodes across the Internet, leaving it vulnerable to eavesdropping. Another consideration is the sender might not want the message to be readable - even by the intended recipient - after some time or after it's been read once. There are a number of reasons for this; for example, the message might

C# Export Private/Public RSA key from RSACryptoServiceProvider to PEM string

て烟熏妆下的殇ゞ 提交于 2020-01-26 08:46:23
问题 I have an instance of System.Security.Cryptography.RSACryptoServiceProvider, i need to export it's key to a PEM string - like this: -----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQDUNPB6Lvx+tlP5QhSikADl71AjZf9KN31qrDpXNDNHEI0OTVJ1 OaP2l56bSKNo8trFne1NK/B4JzCuNP8x6oGCAG+7bFgkbTMzV2PCoDCRjNH957Q4 Gxgx1VoS6PjD3OigZnx5b9Hebbp3OrTuqNZaK/oLPGr5swxHILFVeHKupQIDAQAB AoGAQk3MOZEGyZy0fjQ8eFKgRTfSBU1wR8Mwx6zKicbAotq0CBz2v7Pj3D+higlX LYp7+rUOmUc6WoB8QGJEvlb0YZVxUg1yDLMWYPE7ddsHsOkBIs7zIyS6cqhn0yZD VTRFjVST

How can I check the parity of a DES key?

寵の児 提交于 2020-01-26 04:24:09
问题 I am working on the DES (Data Encryption Standard) algorithm in my Cryptography class, as a part of which I have to write a C code which includes a function to check the parity of a DES key. How can I do this? 回答1: I would just do a Google search, and pick one of the first results that comes up. Taken from the above link: bool AdjustDESKeyParity(UCHAR* pucKey, int nKeyLen) { int cPar; for(int i = 0; i < nKeyLen; i++) { cPar = 0; for(int j = 0; j < DES::BLOCKSIZE; j++) { if(pucKey[i] & (0×01 <

How to properly use setSeed() method in SecureRandom to generate RSA primes

不羁岁月 提交于 2020-01-25 15:12:29
问题 I want to produce the two prime numbers for RSA key generation. I think in order to increase both primes' randomness, the random may be generated as the following: SecureRandom r = SecureRandom.getInstance("SHA1PRNG"); r.setSeed(1232); p = BigInteger.probablePrime(1024, r); q = BigInteger.probablePrime(1024, r); My question is: Do you think using SecureRandom will increase the p and q randomness? If so, how can I randomly set the value of setSeed() instead of making it a fixed value ( here i

How to properly use setSeed() method in SecureRandom to generate RSA primes

感情迁移 提交于 2020-01-25 15:12:04
问题 I want to produce the two prime numbers for RSA key generation. I think in order to increase both primes' randomness, the random may be generated as the following: SecureRandom r = SecureRandom.getInstance("SHA1PRNG"); r.setSeed(1232); p = BigInteger.probablePrime(1024, r); q = BigInteger.probablePrime(1024, r); My question is: Do you think using SecureRandom will increase the p and q randomness? If so, how can I randomly set the value of setSeed() instead of making it a fixed value ( here i

PayPal IPN username/password hashing, how does it work?

自作多情 提交于 2020-01-25 10:44:05
问题 I'm trying to make use of the PayPal Subscription with IPN to provide monthly billing for my customers. The IPN works fine but I am not sure how the password hashing works. username (optional) Username generated by PayPal and given to subscriber to access the subscription. 64 password (optional) Password generated by PayPal and given to subscriber to access the subscription (password will be encrypted). My understanding was that I need to 'hash' the real password and then compare it with the

PyCryptodome Error: MAC Check Failed

大憨熊 提交于 2020-01-25 06:41:07
问题 I am working on an encryption program with Pycryptodome in Python 3. I am trying to encrypt a (byte) string and then decrypt it and verify the MAC tag. When I get to verify it, an error is thrown. This is the code: from Crypto.Cipher import AES from Crypto.Random import get_random_bytes aes_key = get_random_bytes(24) aes_cipher = AES.new(aes_key, AES.MODE_GCM) encrypted, MACtag = aes_cipher.encrypt_and_digest(b"A random thirty two byte string.") # Imagine this is happening somewhere else new

PyCryptodome Error: MAC Check Failed

丶灬走出姿态 提交于 2020-01-25 06:40:46
问题 I am working on an encryption program with Pycryptodome in Python 3. I am trying to encrypt a (byte) string and then decrypt it and verify the MAC tag. When I get to verify it, an error is thrown. This is the code: from Crypto.Cipher import AES from Crypto.Random import get_random_bytes aes_key = get_random_bytes(24) aes_cipher = AES.new(aes_key, AES.MODE_GCM) encrypted, MACtag = aes_cipher.encrypt_and_digest(b"A random thirty two byte string.") # Imagine this is happening somewhere else new