aes

Storing AES Secret key using keystore in java

一世执手 提交于 2019-12-03 15:53:29
I am using Java keystore to store the secret key for AES encryption. final String strToEncrypt = "Hello World"; KeyGenerator kg = KeyGenerator.getInstance("AES"); kg.init(128); SecretKey sk = kg.generateKey(); String secretKey = String.valueOf(Hex.encodeHex(sk.getEncoded())); //Storing AES Secret key in keystore KeyStore ks = KeyStore.getInstance("JCEKS"); char[] password = "keystorepassword".toCharArray(); java.io.FileInputStream fis = null; try { fis = new java.io.FileInputStream("keyStoreName"); ks.load(fis, password); } finally { if (fis != null) { fis.close(); } KeyStore

Does AES/CBC really requires IV parameter?

Deadly 提交于 2019-12-03 15:52:38
I am writing a simple app to encrypt my message using AES / CBC (mode). As my understanding CBC mode requires IV parameter but I don't know why my code work without IV parameter used. Anyone can explain why? Thanks. The encrypted message printed: T9KdWxVZ5xStaisXn6llfg== without exception. public class TestAES { public static void main(String[] args) { try { byte[] salt = new byte[8]; new SecureRandom().nextBytes(salt); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); KeySpec keySpec = new PBEKeySpec("myPassword".toCharArray(), salt, 100, 128); SecretKey tmp =

Java 7 Kerberos Issue - AES128 Corrupt checksum

巧了我就是萌 提交于 2019-12-03 15:51:38
I am migrating from Java 6 to Java 7 and am running into a problem with Kerberos authentication. It looks to me that the underlying encryption type order is switched and as a result a different encryption type is used. In this case Aes128CtsHmacSha1EType is being used for part of the transaction when Java 7 is run. ArcFourHmacEType is used when Java 6 is run and for the other part of the Java 7 run. Other details: running on Linux (Fedora 16) against a Windows Active Directory server. I know I can get authentication to work if I set the default_tkt_enctypes, default_tgs_enctypes, permitted

Decrypt .Net cookie in nodejs

巧了我就是萌 提交于 2019-12-03 15:51:09
I've created an encrypted cookie in .Net and I'm trying to decrypt it's content in nodejs. But nodejs keeps throwing the exception "TypeError: DecipherFinal fail" In .Net I'm using the AES encryption method with the key 932D86BB1448EEAA423F38495A2290746D81C27E55D1DC264279537006D6F4CC. My web.config file has the following row <machineKey validationKey="A5326FFC9D3B74527AECE124D0B7BE5D85D58AFB12AAB3D76319B27EE57608A5A7BCAB5E34C7F1305ECE5AC78DB1FFEC0A9435C316884AB4C83D2008B533CFD9" decryptionKey="932D86BB1448EEAA423F38495A2290746D81C27E55D1DC264279537006D6F4CC" validation="SHA1" decryption="AES"

BadPaddingException when decrypting AES with the same key

三世轮回 提交于 2019-12-03 15:00:59
问题 This is the tester: public class CryptographySimpleTests extends ActivityTestCase { public void testsCryptographyClass_encryptAndDecrypt() { final String orgVal = "hi world! :D"; final String key = "key"; try { final byte[] encryptKey = Cryptography.deriveAES256Key(key); final byte[] decryptKey = Cryptography.deriveAES256Key(key); //Deviation method Assert.assertTrue(Arrays.equals(encryptKey, decryptKey)); byte[] encrypted = Cryptography.encryptAES(encryptKey, orgVal.getBytes()); Assert

Test for AES-NI instructions from C#

断了今生、忘了曾经 提交于 2019-12-03 14:47:39
I want to know if there is a way to test for the presence of AES-NI in the host system's CPU from C#.NET. Let me say up front that this question is not asking about how to use AES-NI from .NET. It turns out simply using AESCryptoServiceProvider will use AES-NI if it is available. This result is based on independent benchmarks I did comparing the performances of AESCryptoServiceProvider against the benchmarks provided in TrueCrypt, which does indeed support AES-NI. The results were surprisingly similar on both machines with and without AES-NI. The reason I want to be able to test for it is to

Decryption error on Android 4.4

独自空忆成欢 提交于 2019-12-03 14:16:11
I have algorithm of encryption\ decryption files: private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); byte[] encrypted = cipher.doFinal(clear); return encrypted; } private static byte[] getRawKey(byte[] seed) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("AES"); SecureRandom sr = new SecureRandom(); sr.setSeed(seed); kgen.init(sr); // 192 and 256 bits may not be available SecretKey skey = kgen

AES key derivation function

房东的猫 提交于 2019-12-03 14:08:33
问题 I have a bash script which uses openssl to encrypt data, and Java code which decrypts the result. Based on my earlier post, I'm now able to enter a password in openssl, and copy the resulting key/iv into Java. This relies on using the -nosalt option in openssl. I'd like to remove that option, and take password/salt/iv from openssl and pass it into a JDK key derivation function. Here's the openssl script I'm using: #!/bin/bash openssl enc -aes-128-cbc -in test -out test.enc -p When I run this,

Decrypt AES encrypted file in java

孤人 提交于 2019-12-03 14:04:39
问题 I have a file encrypted with java application using AES. I also have a key file was encrypted with. But i can't understand how to use the key to decrypt file. Most tutorials and examples create temporary random key, encrypt file and decrypt it in one place. So, question is how to specify a key which have to be used for decryption? EDIT : Samples i found use following code to generate key. I have no idea where i can use my key here. KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen

Build openssl with just RSA and AES

北城余情 提交于 2019-12-03 13:42:49
问题 I'm using libcrypto.a (OpenSSL) with a project. By default all the algorithms are available under libcrypto.a. For the project i just need RSA, AES and SHA. How I can build libcrypto.a with just those algorithms? 回答1: If you build OpenSSL by running the config or Configure script, you provide no-<cipher> as an argument to exclude the cipher. Run Configure with no options to see the available build options. The configuration script converts these arguments into options for the preprocessor.