PBEKeySpec what do the iterationCount and keyLength parameters influence?

The iteration count is the number of times that the password is hashed during the derivation of the symmetric key. The higher number, the more difficult it is to validate a password guess and then derive the correct key. It is used together with the salt which is used to prevent against attacks using rainbow … Read more

Do cryptographic hash functions reach each possible values, i.e., are they surjective?

First, let’s point out that SHA-256 does not accept all possible binary strings as input. As defined by FIPS 180-3, SHA-256 accepts as input any sequence of bits of length lower than 2^64 bits (i.e. no more than 18446744073709551615 bits). This is very common; all hash functions are somehow limited in formal input length. One … Read more

AES-NI intrinsics enabled by default?

The flag has a default of true and it will be set to false if the detection fails, so you can simply use +PrintFlagsFinal to see if it is used: My Laptop without AES-NI: C:\>”C:\Program Files\Java\jdk1.7.0_51\bin\java” -XX:+PrintFlagsFinal -version | find “UseAES” bool UseAES = false {product} bool UseAESIntrinsics = false {product} java version “1.7.0_51” Java(TM) … Read more

Git is moving to new hashing algorithm SHA-256 but why git community settled on SHA‑256

I have presented that move in “Why doesn’t Git use more modern SHA?” in Aug. 2018 The reasons were discussed here by Brian M. Carlson: I’ve implemented and tested the following algorithms, all of which are 256-bit (in alphabetical order): BLAKE2b (libb2) BLAKE2bp (libb2) KangarooTwelve (imported from the Keccak Code Package) SHA-256 (OpenSSL) SHA-512/256 (OpenSSL) … Read more

SecureRandom: init once or every time it is needed?

Unlike the java.util.Random class, the java.security.SecureRandom class must produce non-deterministic output on each call. What that means is, in case of java.util.Random, if you were to recreate an instance with the same seed each time you needed a new random number, you would essentially get the same result every time. However, SecureRandom is guaranteed to … Read more

How to encrypt text with a password in python?

Here’s how to do it properly in CBC mode, including PKCS#7 padding: import base64 from Crypto.Cipher import AES from Crypto.Hash import SHA256 from Crypto import Random def encrypt(key, source, encode=True): key = SHA256.new(key).digest() # use SHA-256 over our key to get a proper-sized AES key IV = Random.new().read(AES.block_size) # generate IV encryptor = AES.new(key, AES.MODE_CBC, … Read more

Java: How to create SHA-1 for a file?

Use the MessageDigest class and supply data piece by piece. The example below ignores details like turning byte[] into string and closing the file, but should give you the general idea. public byte[] createSha1(File file) throws Exception { MessageDigest digest = MessageDigest.getInstance(“SHA-1”); InputStream fis = new FileInputStream(file); int n = 0; byte[] buffer = new … Read more

Javascript: Generate a random number within a range using crypto.getRandomValues

IMHO, the easiest way to generate a random number in a [min..max] range with window.crypto.getRandomValues() is described here. An ECMAScript 2015-syntax code, in case the link is TL;TR: function getRandomIntInclusive(min, max) { const randomBuffer = new Uint32Array(1); window.crypto.getRandomValues(randomBuffer); let randomNumber = randomBuffer[0] / (0xffffffff + 1); min = Math.ceil(min); max = Math.floor(max); return Math.floor(randomNumber * … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)