search
HomeBackend DevelopmentPHP Tutorialasp用自带的RSA方法加密的密文能不能用PHP自带的RSA解密出来

现在是这样的,这边(公司A)有一个东西以前外包给公司B做了,那边用的是ASP,公司这边用的是PHP,
现在使用现在B需要,现在A生成了私钥和公钥(参考http://blog.csdn.net/clh604/article/details/20224735),提供给B公钥,请问B用asp中的rsa加密函数和这个公钥加密出来的密文,A能不能用php自带的rsa解密函数和私钥解出来
菜鸟没分,求有相关经验的大神解惑(主要是PHP和ASP中的RSA算法是不是共通的?)


回复讨论(解决方案)

现在是这样的,这边(公司A)有一个东西以前外包给公司B做了,那边用的是ASP,公司A这边用的是PHP,
现在A生成了私钥和公钥(参考http://blog.csdn.net/clh604/article/details/20224735),提供给B公钥,请问B用asp中的rsa加密函数和这个公钥加密出来的密文,A能不能用php自带的rsa解密函数和私钥解出来
菜鸟没分,求有相关经验的大神解惑(主要是PHP和ASP中的RSA算法是不是共通的?)

asp 没有提供加密算法,asp.net 提供了加密算法
如果 asp 使用的是依据加密算法摹写的,那么除非能实现到 php 的移植,一般不可用php提供的加密函数

asp 没有提供加密算法,asp.net 提供了加密算法
如果 asp 使用的是依据加密算法摹写的,那么除非能实现到 php 的移植,一般不可用php提供的加密函数


这个私钥和公钥是openssl生成的,B用c#和这个公钥将一段字符串加密之后的密文,A能用私钥和PHP解开吗

理论上是可以的,只要算法实现上是一样的
你应该给出 C# 的代码、公钥与私钥和若干组明文和密文

理论上是可以的,只要算法实现上是一样的
你应该给出 C# 的代码、公钥与私钥和若干组明文和密文



//私钥
$private_key = '-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQCpQ6CMgJe7NmXHpNPFcqdX1hsZQZH5j3WN2hRdfBTG5nQH8ifS
4+BVqifL0JjuffZdHJXqGQon4HD9i64cQ6Ps0kgbAMfNWsvhC+IJYAfH7hBRmB/d
1J4Bucr0o+diWp+7Vmp+QS9H5n6WxvSYglySFXvn5Z5FStWZGuoO3VgIwQIDAQAB
AoGAXvGRJ96lvZyIwNCi/TkPxwRRFPyjvgGLZfMywzFrkhoIccCSOAgceNDGG9w5
PGWpgJcdPD+pY67Qklf8ZNxIIQ/CYO+YB20dyio138jNLFTRmvUbzkK+9g1h0LF1
ksbK5sfTPLplK4lKbowDK9XiuSGJThOiN5qEiiWCNMlgowECQQDfZhWxVh7jzlyU
MuLvc8ZzgSdNJaH3upx8asFspvqXFpuj/GYaMuEwFfT4Mz9QTgT8zeaij/zpivTN
I3bEKeYRAkEAwfcjLb75RSCUKD1d84cUcQauZmyCRymu/C4/Whxr1AO0lIUc94cU
sgkdxqMnbJPca5+rQE9aDmf9cslUMj2HsQJAIh1cwq/8F52z1Y3PyfFMJOdcMRPG
ICaHLxi+YPE+40O4kNpCXU3XxZgUyLJKwOCpMlHfHoQOgzuNFqaLxHkBgQJAW6Rc
Zpy4QUTnOyvjW9AShGRXueTCmMTE/DkNjZGoEH+/rfxGd1zHFmbgPp2PXultVxwV
WUkkj3HqeXVN5n7TwQJAaySbpZjetKJjx33a/jbLY26OczTtAw5t4FK84x8ka29r
wEuqs5+e2eanroktyeiLi8j/difKHDSWdTD+TiJqoA==
-----END RSA PRIVATE KEY-----';
//公钥
$public_key = '-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCpQ6CMgJe7NmXHpNPFcqdX1hsZ
QZH5j3WN2hRdfBTG5nQH8ifS4+BVqifL0JjuffZdHJXqGQon4HD9i64cQ6Ps0kgb
AMfNWsvhC+IJYAfH7hBRmB/d1J4Bucr0o+diWp+7Vmp+QS9H5n6WxvSYglySFXvn
5Z5FStWZGuoO3VgIwQIDAQAB
-----END PUBLIC KEY-----';

<?phpheader("Content-Type: text/html; charset=utf-8");//私钥$private_key = '-----BEGIN RSA PRIVATE KEY-----MIICWwIBAAKBgQCpQ6CMgJe7NmXHpNPFcqdX1hsZQZH5j3WN2hRdfBTG5nQH8ifS4+BVqifL0JjuffZdHJXqGQon4HD9i64cQ6Ps0kgbAMfNWsvhC+IJYAfH7hBRmB/d1J4Bucr0o+diWp+7Vmp+QS9H5n6WxvSYglySFXvn5Z5FStWZGuoO3VgIwQIDAQABAoGAXvGRJ96lvZyIwNCi/TkPxwRRFPyjvgGLZfMywzFrkhoIccCSOAgceNDGG9w5PGWpgJcdPD+pY67Qklf8ZNxIIQ/CYO+YB20dyio138jNLFTRmvUbzkK+9g1h0LF1ksbK5sfTPLplK4lKbowDK9XiuSGJThOiN5qEiiWCNMlgowECQQDfZhWxVh7jzlyUMuLvc8ZzgSdNJaH3upx8asFspvqXFpuj/GYaMuEwFfT4Mz9QTgT8zeaij/zpivTNI3bEKeYRAkEAwfcjLb75RSCUKD1d84cUcQauZmyCRymu/C4/Whxr1AO0lIUc94cUsgkdxqMnbJPca5+rQE9aDmf9cslUMj2HsQJAIh1cwq/8F52z1Y3PyfFMJOdcMRPGICaHLxi+YPE+40O4kNpCXU3XxZgUyLJKwOCpMlHfHoQOgzuNFqaLxHkBgQJAW6RcZpy4QUTnOyvjW9AShGRXueTCmMTE/DkNjZGoEH+/rfxGd1zHFmbgPp2PXultVxwVWUkkj3HqeXVN5n7TwQJAaySbpZjetKJjx33a/jbLY26OczTtAw5t4FK84x8ka29rwEuqs5+e2eanroktyeiLi8j/difKHDSWdTD+TiJqoA==-----END RSA PRIVATE KEY-----';//公钥$public_key = '-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCpQ6CMgJe7NmXHpNPFcqdX1hsZQZH5j3WN2hRdfBTG5nQH8ifS4+BVqifL0JjuffZdHJXqGQon4HD9i64cQ6Ps0kgbAMfNWsvhC+IJYAfH7hBRmB/d1J4Bucr0o+diWp+7Vmp+QS9H5n6WxvSYglySFXvn5Z5FStWZGuoO3VgIwQIDAQAB-----END PUBLIC KEY-----';$pi_key =  openssl_pkey_get_private($private_key);//这个函数可用来判断私钥是否是可用的,可用返回资源id Resource id$pu_key = openssl_pkey_get_public($public_key);//这个函数可用来判断公钥是否是可用的$data = "{from:jinhua,to:rayo,dongid:dasdd,dongcode:hajshh,type:4,posttime:2014-08-21}";//原始数据,明文$encrypted = "";$decrypted = "";echo "原始数据:",$data,"<BR>";echo "私钥加密:<br>";openssl_private_encrypt($data,$encrypted,$pi_key);//私钥加密$encrypted = base64_encode($encrypted);//加密后的内容通常含有特殊字符,需要编码转换下,在网络间通过url传输时要注意base64编码是否是url安全的echo $encrypted,"<br>";echo "公钥解密:<br>";openssl_public_decrypt(base64_decode($encrypted),$decrypted,$pu_key);//私钥加密的内容通过公钥可用解密出来echo $decrypted,"<br>";echo "公钥加密:<br>";openssl_public_encrypt($data,$encrypted,$pu_key);//公钥加密$encrypted = base64_encode($encrypted);echo $encrypted,"<br>";echo "私钥解密:<br>";openssl_private_decrypt(base64_decode($encrypted),$decrypted,$pi_key);//私钥解密echo $decrypted,"<br>";?>

结果:

你确定这样的加密可以成功吗,明文长度不会超长报错吗,我现在用了个分段加密,传到JAVA那边,返回来的密文解不开了,蛋疼

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

How to Register and Use Laravel Service ProvidersHow to Register and Use Laravel Service ProvidersMar 07, 2025 am 01:18 AM

Laravel's service container and service providers are fundamental to its architecture. This article explores service containers, details service provider creation, registration, and demonstrates practical usage with examples. We'll begin with an ove

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Customizing/Extending Frameworks: How to add custom functionality.Customizing/Extending Frameworks: How to add custom functionality.Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function