aes

Encrypt and decrypt doesn't give the same plain text using AES/ECB/NoPadding

落爺英雄遲暮 提交于 2019-12-03 21:28:06
String plain1= "Test"; byte[] cipher = SplashSecure.getInstance().encrypt2(plain1); String plain2 = SplashSecure.getInstance().decrypt2(cipher); plain = Test������������������������ After decryption plainText2 should be equal to plaintext . But it's not. Encrypt/Decrypt methods. public void initKey(String key) { String paddedKey = Utils.padString(key); mKeyspec = new SecretKeySpec(Utils.getBytes(paddedKey), "AES/ECB/NoPadding"); // Utils.getBytes returns "paddedKey.getBytes("CP1252")" } public byte[] encrypt2(String data) { try { Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding"); cipher

Symmetric encryption (AES) in Apache Thrift

不打扰是莪最后的温柔 提交于 2019-12-03 21:27:45
I have two applications that interact using Thrift. They share the same secret key and I need to encrypt their messages. It makes sense to use symmetric algorithm (AES, for example), but I haven't found any library to do this. So I made a research and see following options: Use built-in SSL support I can use built-in SSL support, establish secure connection and use my secret key just as authentication token. It requires to install certificates in addition to the secret key they already have, but I don't need to implement anything except checking that secret key received from client is the same

JAVA AES 256 Decrypt [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-03 21:11:19
This question already has answers here : Closed 2 years ago . InvalidKeyException Illegal key size (5 answers) I'm trying to decrypt with AES some data. I've been given a 256 bit key and 16 byte IV like these: String key = "Hh1s1f4T2mpN3yCh4ngeL8t3r\\.Thxpp"; int[] v = {11, 1, 555, 222, 241, 21, 11, 33, 35, 91, 45, 6, 14, 30, 22, 234}; String IV = Arrays.toString( v ); I've been told the padding should be PKCS7 but when I init the cipher with AES/CBC/PKCS7PADDING it says: Cannot find any provider supporting AES/CBC/PKCS7PADDING If I use AES/CBC/PKCS5PADDING I get Illegal key size but I've

Java encrypt AES, PHP decrypt AES

女生的网名这么多〃 提交于 2019-12-03 21:05:58
I was looking for a way to encrypt a string in Java, and decrypt it in PHP. I found this in an answer somewhere on Stackoverflow and I modified it to do the exact opposite. This is my code to encrypt in Java: public static String encrypt(String data, String initialVectorString, String secretKey) { String encryptedData = null; try { SecretKeySpec skeySpec = new SecretKeySpec(md5(secretKey).substring(0, 16).getBytes(), "AES"); IvParameterSpec initialVector = new IvParameterSpec(initialVectorString.getBytes()); Cipher cipher = Cipher.getInstance("AES/CFB8/NoPadding"); cipher.init(Cipher.ENCRYPT

Random access of encrypted data AES GCM mode

人走茶凉 提交于 2019-12-03 21:02:06
There is a very good example for random access AES CTR mode and it works: Random access InputStream using AES CTR mode in android private static final int AES_BLOCK_SIZE = 16; private static IvParameterSpec calculateIVForOffset(final IvParameterSpec iv, final long blockOffset) { final BigInteger ivBI = new BigInteger(1, iv.getIV()); final BigInteger ivForOffsetBI = ivBI.add(BigInteger.valueOf(blockOffset / AES_BLOCK_SIZE)); final byte[] ivForOffsetBA = ivForOffsetBI.toByteArray(); final IvParameterSpec ivForOffset; if (ivForOffsetBA.length >= AES_BLOCK_SIZE) { ivForOffset = new IvParameterSpec

Java AES decryption BadPaddingException

十年热恋 提交于 2019-12-03 20:47:34
note: Java NOOB. Alright, I know this has been answered a few dozen times on here, but the solutions don't seem to work/apply directly to where I understand them. (Yes, I know I don't completely understand encryption/decryption, AES, etc. but that is not the point, I am trying to understand this) I have a utility api where I want to pass a string and return an encrypted string. Then I want to pass the encrypted string, and return a decrypted string. Simple. It works fine for many strings I pass in, but on some, I'm getting the exception javax.crypto.BadPaddingException: Given final block not

CMDB和自动化运维

陌路散爱 提交于 2019-12-03 20:47:01
CMDB和自动化运维 IT运维的分类 IT运维,指的是对已经搭建好的网络,软件,硬件进行维护。运维领域也是细分的,有硬件运维和软件运维 硬件运维主要包括对基础设施的运维,比如机房的设备,主机的硬盘,内存这些物理设备的维护 软件运维主要包括系统运维和应用运维,系统运维主要包括对OS,数据库,中间件的监控和维护,这些系统介于设备和应用之间,应用运维主要是对线上业务系统的运维 这里讨论的主要是软件运维的自动化,包括系统运维和应用运维的自动化 传统运维痛点 日常工作繁琐 日常运维工作是比较繁琐的,研发同学会经常需要到服务器上查日志,重启应用,或者是说今天上线某个产品,需要部署下环境。这些琐事是传统运维的大部分工作 应用运行环境不统一 在部署某应用后,应用不能访问,就会听到开发人员说,在我的环境运行很好的,怎么部署到测试环境后,就不能用了,因为各类环境的类库不统一 还有一种极端情况,运维人员习惯不同,可能凭自己的习惯来安装部署软件,每种服务器上运行软件的目录不统一 运维及部署效率低下 想想运维人员需要登陆到服务器上执行命令,部署程序,不仅效率很低,并且非常容易出现人为的错误,一旦手工出错,追溯问题将会非常不容易 无用报警信息过多 经常会收到很多报警信息,多数是无用的报警信息,造成运维人员经常屏蔽报警信 另外如果应用的访问速度出了问题,总是需要从系统、网络、应用、数据库等一步步的查找原因

How to handle the IV/Nonce/Counter for AES CTR?

瘦欲@ 提交于 2019-12-03 20:41:53
import javax.crypto.Cipher; public abstract class Crypto { private static final String CIPHER_ALGORITHM = "AES/CTR/NoPadding"; private String AesKeyString = "ByWelFHCgFqivFZrWs89LQ=="; private void setKey() throws NoSuchAlgorithmException{ byte[] keyBytes; keyBytes = Base64.getDecoder().decode(AesKeyString); aesKey = new SecretKeySpec(keyBytes, "AES"); } protected byte[] execute(int mode, byte[] target, byte[] iv) throws Exception{ Cipher cipher = Cipher.getInstance(CIPHER_ALGORITHM); IvParameterSpec ivSpec = new IvParameterSpec(iv); cipher.init(mode, aesKey, ivSpec); return cipher.doFinal

AES 256 Encryption Issue

半世苍凉 提交于 2019-12-03 20:33:23
问题 The following code perfectly implements AES-128 encryption/decryption. public static void main(String[] args) throws Exception { String input = JOptionPane.showInputDialog(null, "Enter your String"); System.out.println("Plaintext: " + input + "\n"); // Generate a key KeyGenerator keygen = KeyGenerator.getInstance("AES"); keygen.init(128); byte[] key = keygen.generateKey().getEncoded(); SecretKeySpec skeySpec = new SecretKeySpec(key, "AES"); // Generate IV randomly SecureRandom random = new

What makes AES with Base64 generate different encryption result for the same plain text?

早过忘川 提交于 2019-12-03 20:29:11
Here's a sample dummy code called test(), I run this 100K times and I get different encrypted messages for the same plain text (obviously, the decryption I get is the original plain text). I guess the reason behind this is to avoid frequency; but how come there can be MANY encryption to ONE decryption? shouldn't it be a one to one? public static void test() { String plainMessage = "I'm gonna bid 100 USD on this project"; String password = "A99922000001000004581F0F0CCD0000"; Set<String> set = new HashSet<String>(); for (int x=0; x<100000; x++) { String enc = AESEncryption.encryptMessage