how to use OpenSSL to decrypt Java AES-encrypted data?
Question:
I'm interfacing to a legacy Java application (the app cannot be changed) which is encrypting data using AES. Here is how the original Java code is instantiating the AES cipher:
SecretKeySpec skeySpec = new SecretKeySpec(key, "AES"); cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec );
I'm a C/C++ developer, not Java, but from what I can tell this legacy Java code is not specifying the mode, nor the initialization vector. Anyone happen to know what Java would be using by default since it isn't specified?
We need the new C/C++ app to decrypt the Java-encrypted data. But I'm at a loss as to what to use for OpenSSL's initialization vector and chaining mode since I don't know what java does.
Answer:
Possible answer found:
"By default, Java Ciphers (at least in Sun's implementations) are constructed in what is called Electronic Codebook (ECB) mode."
(Source: http://www.javamex.com/tutorials/cryptography/block_modes.shtml)
So if ECB is used by default, I guess that means no initialization vector, and I can use the following method from OpenSSL:
void AES_ecb_encrypt(*in, *out, *key, enc);
Using AES_decrypt()
I can decrypt 1000+ byte messages that originated on the Java side. So it looks like Java does indeed default to ECB mode with no initialization vector. However, I still cannot encrypt and send a new message to the Java app.
Investigation continues.
Got it all working. Thanks for the numerous hints. I can confirm Java uses
ECB
by default. All padding bytes are set to the number of bytes added (which is known as PKCS5-padding)."Hello World"
-> encrypted by Java -> decrypted using OpenSSL will look like"Hello World\5\5\5\5\5"
.
相關推薦
how to use OpenSSL to decrypt Java AES-encrypted data?
Question: I'm interfacing to a legacy Java application (the app cannot be changed) which is encrypting data using AES. Here is how the or
How to use GITHUB to do source control
GITHUB sourcecontrolhow to create repository how to create branch how to add the comment for every change what is the commit how to rollback how to sync th
How to use script to get all oracle EBS Form name and corres
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!  
How Microsoft plans to use AI to impact the entertainment industry
Artificial intelligence (AI) tends to divide public opinion; some favor the developments made in tech, while others worry we've gone too far. Tony Emerson,
How to Use Checklists to Improve Your UX
How to Use Checklists to Improve Your UXAccording to data published by researchers at the Harvard T.H. Chan School of Public Health, more than 234 million
How to use Paperspace to train your Deep Neural Networks
First, you have to sign up for the service. One tip here: students of the fast.ai course get a promo code, which is worth $15. That’s up to about 30 hours
How to Use React to display NASA’s Astronomy Picture of the Day
How to Use React to display NASA’s Astronomy Picture of the DayGoal: Display NASA’s Astronomy Picture of the Day from the date a user inputsIn my first wee
How to Use Postman to Test an API During Development
REST APIs have become the new standard in providing a public and secure interface for your service. Though REST has become ubiquitous, it's no
How I use Python to blog from my iPhone
1. I write each article in MarkdownMarkdown is a simple syntax that can be easily translated to HTML (and a bunch of other formats), but only requires a si
How to Use Power Transforms for Time Series Forecast Data with Python
Tweet Share Share Google Plus Data transforms are intended to remove noise and improve the signa
How to Use NSLog to Debug CGRect and CGPoint
CGPoint and CGRect are structures (versus objects) and therefore the old NSLog standby %@ will not work as expected. Here is how each structure is defined
How-to: use spark to suport query across mysql tables and hbase tables
To resolve this, one good choice is spark whose parquet support and dataframe resolved this problem. Parquet is a good choice for performance consideration
Google to use AI to predict natural disasters
Google has provided a service for many years which provides alerts about natural disasters. This has been in the form of warnings provided by government ag
Sanofi taps startup Researchably to use AI to sift through new research
Researchably, a young startup incubated at UC Berkeley, is conducting a pilot with Sanofi in China, using AI to sift through thousands of research studies
60% Indian businesses plan to use AI to automate tasks: Survey
Bengaluru: While nearly 60 per cent business leaders in India are planning to use Artificial Intelligence (AI) to automate tasks to a large extent, 20 per
Civil Wants to Use Blockchain to Fund Journalism. Can it Work?
Civil Wants to Use Blockchain to Fund Journalism. Can it Work?The start-up is trying to combat fake news and win over a new generation of readersBy Hannah
The World Bank and tech companies want to use AI to predict famine
At this week's United Nations General Assembly, the World Bank, the United Nations, and the Red Cross teamed up with tech giants Amazon, Microsoft, and Goo
[Selenium+Java] How to use IntelliJ IDEA & Selenium Webdriver
sts quick public das nes www. button margin state Original URL: https://www.guru99.com/intellij-selenium-webdriver.html How to use Int
How To Use Simple Factory Design Pattern In Java
Simple Factory Design Pattern is one of the many design patterns – best practices on how to solve common problems. Design Patterns were made popular by
How to use this image - Redis
art compile clu contain ext nal nds iat pop link - https://store.docker.com/images/redis?tab=description start a redis instance $ docker