How to decrypt strings encrypted by Java using DES in PHP?
Detailed explanation of PHP decryption Java DES encryption string
Cross-language data interaction and encryption and decryption are common challenges in development. This article takes Java's DES encryption and PHP decryption as an example to explain in detail how to solve such problems.
Java encryption process
Assume that the Java side uses the key "sg202303" encryption string"> This article participated in the segmentfault interview challenge. You who are reading it are welcome to join. ". The code snippet is as follows:
final String key = "sg202303"; final String value = "> This article has participated in the segmentfault interview challenge. You who are reading are welcome to join."; final byte[] encrypt = SecureUtil.des(key.getBytes(StandardCharsets.UTF_8)).encrypt(value); final String encode = Base64.encode(encrypt); System.out.println(encode);
The encryption result is:
<code>p fee0nngtu8ak1e78zggds3ozpa m6h1u8v/fmih/wi1k3ym/q in 3wugtv1xghvibxcrypqofv5ih0bn vztf2fnt4vbh59ertaqoyl 4eprktvf1fngtbcbat3chnayvuixmbsauplwpcgmhjlqm6k4qbzqnendrimczkkyk413alliuy2/fo97pvgdr</code>
PHP decryption process
The PHP side uses the openssl_decrypt
function to decrypt Base64 encoded strings. The key and encryption mode must be consistent with the Java side. The code is as follows:
$encrypted = 'P fEE0NngTu8Ak1E78zGGds3ozPA M6h1u8v/FMih/Wi1k3YM/q In 3wUgTv1XGhViBxCRYpqofV5ih0BN vZTf2fnT4VbH59eRTAQoyl 4ePrKtVf1FngTbcBAT3CHNaYVUIXMbsAUpLwpcgMhJlqM6k4qbzqnEndrIMCzkkyk413alLIUy2/Fo97PvGdR'; $method = 'DES-ECB'; $key = 'sg202303'; $decrypted = openssl_decrypt($encrypted, $method, $key); var_dump($decrypted);
This code successfully decrypts Java encrypted data, realizing cross-language data secure transmission and processing. It should be noted that the DES encryption algorithm is relatively low in security, and it is recommended to use a more secure encryption algorithm, such as AES in practical applications.
The above is the detailed content of How to decrypt strings encrypted by Java using DES in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use Vue for data encryption and secure transmission Introduction: With the development of the Internet, data security has received more and more attention. In web application development, data encryption and secure transmission are important means to protect user privacy and sensitive information. As a popular JavaScript framework, Vue provides a wealth of tools and plug-ins that can help us achieve data encryption and secure transmission. This article will introduce how to use Vue for data encryption and secure transmission, and provide code examples for reference. 1. Data encryption and data encryption

Compilation|Produced by Xingxuan|51CTO Technology Stack (WeChat ID: blog51cto) In the past two years, I have been more involved in generative AI projects using large language models (LLMs) rather than traditional systems. I'm starting to miss serverless cloud computing. Their applications range from enhancing conversational AI to providing complex analytics solutions for various industries, and many other capabilities. Many enterprises deploy these models on cloud platforms because public cloud providers already provide a ready-made ecosystem and it is the path of least resistance. However, it doesn't come cheap. The cloud also offers other benefits such as scalability, efficiency and advanced computing capabilities (GPUs available on demand). There are some little-known aspects of deploying LLM on public cloud platforms

In web development, a 401 Unauthorized error means that the client is not authorized to access a specific resource. PHP provides multiple processing methods: 1. Use 401 HTTP status code; 2. Output JSON response; 3. Redirect to the login page. To enhance security, you can take the following measures: 1. Use HTTPS; 2. Enable CSRF protection; 3. Implement input validation; 4. Use an authorization framework.

MySQL and Oracle: Comparison of support for data encryption and secure transmission Introduction: Data security has become increasingly important in today's information age. From personal privacy to business secrets, maintaining the confidentiality and integrity of data is critical for any organization. Among database management systems (DBMS), MySQL and Oracle are the two most popular options. In this article, we will compare the extent to which MySQL and Oracle support data encryption and secure transmission, and provide some code examples.

I have a gohttp server. I want to secure my routes using azurejwt token. I am able to generate the token but cannot verify it. This is what I do: packagemainimport("context""errors""fmt""github.com/dgrijalva/jwt-go""github.com/lestrrat-go/jwx/jwa""github.com/lestrrat-go/ jwx/jwk"njwt"github.com

We have to use tls1.2 to connect to our mysql server. In our java application we use the following jdbcurl-jdbc:mysql://xxxx-001-dev.cluster-xx-2.rds.amazonaws.com/bats?**enabledtlsprotocols=tlsv1.2** in our When connecting to mysql in my go application, I cannot achieve a similar configuration - cfg1:=mysql.config{user:"adm

On Unix or Linux operating systems, the scp utility (securecopy) is similar to the better-known command cp, but is used to transfer files and directories between hosts over a secure, encrypted network. Since it relies on ssh for data transfer, it provides the same security and uses the same authentication as ssh. Unlike rcp, the scp command will prompt you for a password for authentication if required. In this article, we will delve into secure file transfer in Linux and learn how to use the scp command. With detailed explanations and example use cases of common scp switches and options, you'll learn how to use this utility. It's important to know the following before you start since scp relies on s

In today's information age, data security is an important task faced by every enterprise, organization and individual. Linux systems have become the operating system of choice for most enterprises and organizations, so data encryption and secure transmission of Linux systems have become increasingly necessary. This article will introduce how to encrypt and secure data transmission in Linux systems, and provide detailed code examples. 1. Data Encryption Data encryption is a reliable security measure that can convert sensitive data into ciphertext that is difficult to read and understand, thus ensuring that the data
