Questions tagged [cryptography]

CRYPTOGRAPHY MUST BE PROGRAMMING RELATED. Cryptography covers, among other things, symmetric and asymmetric encryption, hashing, and digital signatures. Cryptography questions not directly related to software development are better asked at crypto.stackexchange.com.

CRYPTOGRAPHY MUST BE PROGRAMMING RELATED.

Cryptography (from the Greek for "secret/hidden writing") is the practice and study of techniques for secure communication and processing in the presence of third parties. There are general three properties that we associate with secure communication:

  • confidentiality: some information must be stored or transferred without permitting unauthorized entities to read it;
  • integrity: some information must be stored or transfered without allowing any alteration by an unauthorized entity to go unnoticed;
  • authenticity: some information must be stored or transferred in such a way that the originator of the information can be verified, in a way which unauthorized entities cannot falsify.

"Entities" are persons, roles or systems which are supposed to be distinct from each other according to some definition. Cryptography operates in the logical world of computers, from which the physical world is out of reach; anybody can buy a PC, so what distinguishes one user on a network from another (as seen through a network or any other communication protocol) is what that user knows. Cryptography calls such knowledge as a secret or key: this is a piece of secret data, which is used as parameter to a cryptographic algorithm that implements a cryptographic property with regards to the key.

For instance, symmetric encryption is about transforming some data (possibly a huge file), using a (normally short) key, into an encrypted form which shows no readable structure anymore, but such that the transformation can be reversed (recovering the original data from the encrypted form) if the encryption key is known. In a way, symmetric encryption concentrates confidentiality into the key, which can be short enough to be manageable (e.g. the key might be memorized by a human being, in which case it is called a password).

The cryptographic algorithms themselves are public, if only because nobody can really tell "how much" a given algorithm is secret, since algorithms are often implemented as software or hardware systems which are duplicated into many instances, and the cost of reverse engineering is hard to estimate. A cryptosystem (combination of an algorithm and its key) is then split into the algorithm, which is embodied as an implementation, and a key, for which security can be quantified (e.g. by counting the number of possible keys of a given length).

Cryptography covers the science of designing cryptographic algorithms (cryptology) and of trying to break them (cryptanalysis); it also encompasses the techniques used to apply the algorithms in various situations, in particular implementation as software, and the related subjects (such as performance issues). Some algorithms consist in the assembly of several sub-algorithms in order to obtain higher level properties (e.g. "a bidirectional tunnel for confidential data with verified integrity and mutual authentication"); they are then called protocols.

Commonly used cryptographic algorithms and protocols include, among others:

  • Symmetric encryption: 3DES, AES, RC4, Blowfish
  • Hash functions: MD5, SHA-1, SHA-2 (includes SHA-256 and SHA-512)
  • Asymmetric encryption: RSA
  • Digital signatures: RSA (similar, but not identical to, the RSA for encryption), DSA (as part of the "DSS" standard), ECDSA
  • Data tunneling: TLS (formerly known as "SSL"; when used to convey HTTP requests, the result is known as "HTTPS"), SSH, IPsec
  • Encrypted and/or signed emails: OpenPGP (standard protocol derived from the original PGP software), S/MIME
  • Certificates: X.509, OpenPGP (certificates are about binding identities to public keys, which are themselves used in asymmetric encryption and digital signatures)
  • Key sharing (or Key exchanging): diffie-hellman, PKI (Protocols and infrastructures to establish cryptographic keys between parties for confidential communication.)

On-topic themes also include password management (storage, verification, entropy, breaking techniques such as rainbow tables...), advanced multi-party protocols (electronic voting schemes, digital cash, anonymous browsing...), usage of existing implementations (libraries, hardware accelerators, smartcards...), and so on.

Questions not directly related to software development (e.g. the more theoretic ones) are better asked in the Cryptography Stack Exchange site (still in beta).

See also: , , ,

14876 questions
5
votes
1 answer

ModuleNotFoundError: No module named 'Crypto'

I installed Crypto module and SHA256 but showing ModuleNotFoundError :- Traceback (most recent call last): File "Digitalsig.py", line 1, in from Crypto.Hash import SHA256 ModuleNotFoundError: No module named 'Crypto' Here is the…
Rahul Thakur
  • 77
  • 1
  • 1
  • 2
5
votes
1 answer

How can I get a NCRYPT_KEY_HANDLE for the private key of a PCCERT_CONTEXT?

How can I get a NCRYPT_KEY_HANDLE for encryption/decryption with CNG from the private key of a PCCERT_CONTEXT from the windows certificate store? The CryptEncrypt function has been superceded by the NCryptEncrypt and BCryptEncrypt functions, but…
jorgen
  • 535
  • 1
  • 5
  • 12
5
votes
4 answers

Using Asymmetric Key on .Net Core

I am trying to run code from this sample https://learn.microsoft.com/en-us/dotnet/standard/security/how-to-store-asymmetric-keys-in-a-key-container Under .NetCore 2.0 (Web application). However when I try to execute any line using CspParameters I…
MHugh
  • 455
  • 1
  • 7
  • 20
5
votes
1 answer

Golang signing a struct using rsa

I have a struct Transaction with the following fields, type Transaction struct { Sender string `json:"sender"` Receiver string `json:"receiver"` Signature string `json:"signature"` Amount int64 `json:"amount"` } I also have…
ashishmax31
  • 151
  • 2
  • 12
5
votes
1 answer

PyCryptodome Error: MAC Check Failed

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…
purple_dot
  • 106
  • 2
  • 9
5
votes
2 answers

How to get PKCS11 PublicKey via Template

I have a GO Application, that stores it's certificate to a HSM via opencryptoki (pkcs11) in a softwaretoken. But it's not a go question, more a general pkcs11 question I think. I set my certificates and privatekey like this: certTemplate :=…
Flo
  • 2,699
  • 4
  • 24
  • 46
5
votes
1 answer

Java vs. Golang for HOTP (rfc-4226)

I'm trying to implement HOTP (rfc-4226) in Golang and I'm struggling to generate a valid HOTP. I can generate it in java but for some reason my implementation in Golang is different. Here are the samples: public static String constructOTP(final Long…
Zach Kauffman
  • 486
  • 1
  • 4
  • 17
5
votes
1 answer

Is there a benefit to padding with random data in AES encryption?

When using AES encryption, plaintext must be padded to the cipher block size. Most libraries and standards use padding where the padding bytes can be determined from the unpadded plaintext length. Is there a benefit to using random padding bytes…
jwhitlock
  • 4,572
  • 4
  • 39
  • 49
5
votes
1 answer

How can I create a slot using the pkcs11-tool?

I am trying to use pkcs11 within my application to access smart cards. Here is the output of the 'list-slots' commands - root@penguin:~/src/tools$ pkcs11-tool -L Available slots: Slot 0 (0xffffffffffffffff): Virtual hotplug slot (empty) I have 2…
ksoop
  • 165
  • 1
  • 4
  • 16
5
votes
1 answer

one way authentication what does timestamp and nonce mean?

http://technet.microsoft.com/en-us/library/cc767123.aspx in this article the client encrypts a timestamp , nounce and destination identity to the destination. I cannot understand what timestamp does here and what is a nounce ?
user581734
  • 1,219
  • 3
  • 15
  • 24
5
votes
6 answers

Python Cryptography Error cannot import name certificate_transparency

trying to run a pymodbus tcp server and im getting this stack trace... at a total loss here so any help is appreciated. Thanks! Traceback (most recent call last): File "Worrking_ModbusJ1939Bridge.py", line 12, in from pymodbus.server.async…
Emerson
  • 270
  • 2
  • 4
  • 11
5
votes
1 answer

Cryptography: Why does my encryption initialization vector only effect the first 16 bytes?

I wanted to try my hand at encrypting a file and utilized the following stack overflow response. However, while testing out the initialization vector, I found it only effected the first 16 bytes. When I pass an empty iv to the decrypt cipher (other…
robertf
  • 237
  • 1
  • 11
5
votes
1 answer

Storing private/secret keys in an Ionic application

How do you go about storing private/secret keys in an Ionic application? I know that with a generic Android application, it is possible with the Android Keystore API or Keychain Services. Some context: I am trying to develop an offline payments…
methuselah
  • 12,766
  • 47
  • 165
  • 315
5
votes
1 answer

AES-128 CBC decryption in Python

I'm trying to implement this code in python (I'm new to python) and it gives me the following error: AttributeError: 'str' object has no attribute 'decode' If we remove .decode ('hex') only to avoid such error: from itertools import product from…
Jon Ander Díez
  • 87
  • 1
  • 1
  • 9
5
votes
3 answers

AES-256-CBC in Java

I'm trying to write a simple Java program that will encrypt plain text with AES-256-CBC. There is class: import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; public class AesCBC { private…
marcelby
  • 83
  • 1
  • 2
  • 5
1 2 3
99
100