我们已经使用mcrypt密码对一些数据进行了加密,BLOWFISH并且模式为CBC
String加密,php5.5并且需要对此进行解密php7.1(已升级php版本)
以下是我们尝试使用openssl解密mcrypt字符串的代码
$data = "Lorem ipsum";
$key = "12345678";
$iv = "12345678";
$encrypted = mcrypt_encrypt(
MCRYPT_BLOWFISH, $key, $data, MCRYPT_MODE_CBC, $iv);
echo $encrypted . PHP_EOL;
$decrypted = openssl_decrypt(
$encrypted, "BF-CBC", $key,
OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
echo $decrypted;
Run Code Online (Sandbox Code Playgroud)
上面的代码没有解密字符串。请建议我任何解密字符串的方法
我一直在尝试使用加密来加密字符串以将其发送到Web服务器,但我一直遇到错误。这是我的功能:
void encRypt(String da){
final key = "my32lengthsupersecretnooneknows1";
final encrypter = new Encrypter(new AES(key));
final encrypted = encrypter.encrypt(da);
print(encrypted);
}
Run Code Online (Sandbox Code Playgroud)
这就是我使用函数的方式:encRypt(chatBody.text); chatBody是一个TextEditingController
这是我的调试控制台:
Launching lib/main.dart on GT I9500 in debug mode...
Built build/app/outputs/apk/debug/app-debug.apk.
I/Timeline(19551): Timeline: Activity_idle id: android.os.BinderProxy@34db68a4 time:15254411
E/ (19551): [android_ws] Format: 5, Width: 1080, Height: 1920
E/ (19551): [android_ws] Format: 5, Width: 1080, Height: 1920
D/ViewRootImpl(19551): ViewPostImeInputStage ACTION_DOWN
D/ViewRootImpl(19551): ViewPostImeInputStage ACTION_DOWN
D/ViewRootImpl(19551): ViewPostImeInputStage ACTION_DOWN
E/flutter (19551): [ERROR:flutter/shell/common/shell.cc(181)] Dart Error: Unhandled exception:
E/flutter (19551): Invalid …Run Code Online (Sandbox Code Playgroud) 我在加密我正在使用的第三方供应商的价值时遇到了问题.
他们的指示如下:
1) Convert the encryption password to a byte array.
2) Convert the value to be encrypted to a byte array.
3) The entire length of the array is inserted as the first four bytes onto the front
of the first block of the resultant byte array before encryption.
4) Encrypt the value using AES with:
1. 256-bit key size,
2. 256-bit block size,
3. Encryption Mode ECB, and
4. an EMPTY initialization vector.
5) After encryption, you should …Run Code Online (Sandbox Code Playgroud) 我有一个客户端服务器应用程序,已经运行了一段时间了.
突然,我尝试从客户端连接时收到以下错误.我发现服务器端没有错误.证书未过期,我没有更改代码.在Google上搜索此错误时,我看不到任何结果.
javax.net.ssl.SSLProtocolException: ChangeCipherSpec message sequence violation
at sun.security.ssl.HandshakeStateManager.changeCipherSpec(Unknown Source)
at sun.security.ssl.Handshaker.receiveChangeCipherSpec(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
at sun.security.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at sun.security.ssl.AppInputStream.read(Unknown Source)
at java.io.DataInputStream.readUnsignedShort(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at java.io.DataInputStream.readUTF(Unknown Source)
at com.jayavon.game.client.cj.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
客户代码:
//load your key store as a stream and initialize a KeyStore
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
//if your store is password protected then declare it (it can be null however)
String tsName = "res/gamedata/truststore";
char[] trustPassword = "--REMOVED--".toCharArray();
//load the …Run Code Online (Sandbox Code Playgroud) 我有一种情况,我需要在Coldfusion中加密内容,然后在Perl中解密.这是一个Coldfusion代码示例:
<cfscript>
input = "Amidst the roar of liberated Rome, Of nations freed, and the world overjoy'd";
encryptionKey = "8kbD1Cf8TIMvm8SRxNNfaQ==";
encryptedInput = encrypt( input, encryptionKey, "AES/ECB/PKCS5Padding", "hex" );
writeOutput( "Encrypted Input: #encryptedInput# <br />" );
</cfscript>
Run Code Online (Sandbox Code Playgroud)
这会产生:
27B0F3EB1286FFB462BDD3F14F5A41724DF1ED888F1BEFA7174CA981C7898ED2EF841A15CDE4332D030818B9923A2DBA0C68C8352E128A0744DF5F9FA955D3C72469FEFDAE2120DE5D74319ED666DDD0
Run Code Online (Sandbox Code Playgroud)
和Perl:
use 5.24.1;
use Crypt::ECB qw(encrypt_hex);
my $input = "Amidst the roar of liberated Rome, Of nations freed, and the world overjoy'd";
my $encryption_key = "8kbD1Cf8TIMvm8SRxNNfaQ==";
my $encrypted_input = encrypt_hex($encryption_key, 'Rijndael', $input);
say $encrypted_input;
Run Code Online (Sandbox Code Playgroud)
这会产生:
e220ff2efe5d41e92237622ba969f35158d20e2c9c44995d44136d928d517462980321d4d6193fe62dc942fd717128442972524207777366954e5ceb2d1812ac997e06767a27d6a0145176d717c3836b
Run Code Online (Sandbox Code Playgroud)
为什么加密内容不同?有没有人对此有任何见解?
由于PHP 7.2中不再支持mcrypt_encrypt,因此我正在尝试完全替换此函数.
在阅读了许多SO答案后,我发现以下代码使用了PHPSECLIB,但它并没有像mcrypt那样生成确切的加密文本.
function encryptRJ256($key,$iv,$string_to_encrypt)
{
// $rtn = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_encrypt, MCRYPT_MODE_CBC, $iv);
$rijndael = new Crypt_Rijndael(CRYPT_RIJNDAEL_MODE_CBC);
$rijndael->setKey($key);
$rijndael->setIV($iv);
$rijndael->setKeyLength(256);
$rijndael->disablePadding();
$rijndael->setBlockLength(256);
$rtn = $rijndael->encrypt($string_to_encrypt);
$rtn = base64_encode($rtn);
return($rtn);
}
Run Code Online (Sandbox Code Playgroud)
我的钥匙和IV是
$ky = 'lkirwf897+22#bbtrm8814z5qq=498j5';
$iv = '741952hheeyy66#cs!9hjv887mxx7@8y';
Run Code Online (Sandbox Code Playgroud)
前42个字符是相同的,但其余的是不同的,你可以看到
要加密的文本:57F0-ECD3-1A3B-341E-BA39-F81B-F020-0DE0
mcrypt_encrypt输出:
3uw7mVZthiIPPNosvppZHd1jEau3Ul + 0BQ4AVS2t80skauq3Zv9z5uztvmiBpYqQcKGIDP5YHfdEBhPBfdVbxg ==phpseclib输出:
3uw7mVZthiIPPNosvppZHd1jEau3Ul + 0BQ4AVS2t80tKnjjxVhuAwh3E1S5OnH1up5AujvQu1Grgyv16tNIEDw ==
我需要生成相同的加密文本,因为这个文本由另一个我无法更改的程序解密.
所以我的问题是,是否可以使用phpseclib或任何其他方式生成与mcrypt_encrypt相同的加密文本?
我创建了一个名为secure的文件夹,在该文件夹中,我有一个文件.htaccess和这些文件.mp4
secure
|--- trailer.mp4
|--- .htaccess
Run Code Online (Sandbox Code Playgroud)
我的档案 .htaccess
RewriteEngine on
RewriteRule ^(.*)/(.*)/(.*)$ file.php?h=$1&t=$2&v=$3
RewriteRule ^$ - [F]
RewriteRule ^[^/]+\.(flv|mp4)$ - [F]
Run Code Online (Sandbox Code Playgroud)
通过此表格,我可以毫无问题地访问文件。
$path = "secure/trailer.mp4";
$size=filesize($path);
$fm=@fopen($path,'rb');
if(!$fm) {
// You can also redirect here
header ("HTTP/1.0 404 Not Found");
die();
}
$begin=0;
$end=$size;
if(isset($_SERVER['HTTP_RANGE'])) {
if(preg_match('/bytes=\h*(\d+)-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) {
$begin=intval($matches[0]);
if(!empty($matches[1])) {
$end=intval($matches[1]);
}
}
}
if($begin>0||$end<$size)
header('HTTP/1.0 206 Partial Content');
else
header('HTTP/1.0 200 OK');
header("Content-Type: video/mp4");
header('Accept-Ranges: bytes');
header('Content-Length:'.($end-$begin));
header("Content-Disposition: inline;");
header("Content-Range: bytes $begin-$end/$size");
header("Content-Transfer-Encoding: …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个简单的Kotlin对象,该对象通过在保存之前对内容进行加密来包装对应用程序共享首选项的访问。
加密似乎可以正常工作,但是当我尝试解密时,我收到一个javax.crypto.AEADBadTagException,它从“ android.security.KeyStoreException:签名/ MAC验证失败”触发。
我尝试调试以查看潜在的问题是什么,但找不到任何东西。没有任何搜索给我任何线索,我似乎遵循了这封信的一些指南,但没有成功。
private val context: Context?
get() = this.application?.applicationContext
private var application: Application? = null
private val transformation = "AES/GCM/NoPadding"
private val androidKeyStore = "AndroidKeyStore"
private val ivPrefix = "_iv"
private val keyStore by lazy { this.createKeyStore() }
private fun createKeyStore(): KeyStore {
val keyStore = KeyStore.getInstance(this.androidKeyStore)
keyStore.load(null)
return keyStore
}
private fun createSecretKey(alias: String): SecretKey {
val keyGenerator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, this.androidKeyStore)
keyGenerator.init(
KeyGenParameterSpec.Builder(alias, KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.build()
)
return keyGenerator.generateKey()
}
private fun getSecretKey(alias: …Run Code Online (Sandbox Code Playgroud) 我有一个加密的字符串及其密钥,它是通过SQL Server使用“ EncryptByPassPhrase”创建的,如何在PHP中对其进行解密?
我已经阅读了“ EncryptByPassPhrase”的文档,该文档指出这是128长度的三重DES加密。我尝试对PHP进行3DES解密,但未返回预期的输出。
MS SQL中的加密是通过
declare @encrypt varbinary(200)
select @encrypt = EncryptByPassPhrase('key', 'taskseq=10000&amt=200.5' )
select @encrypt
Run Code Online (Sandbox Code Playgroud)
我在PHP中将其解密如下:
function decryptECB($encrypted, $key) {
$iv_size = mcrypt_get_iv_size(MCRYPT_3DES, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
// decrypting
$stringText = mcrypt_decrypt(MCRYPT_3DES, $key, $encrypted,
MCRYPT_MODE_ECB, $iv);
return $stringText;
}
Run Code Online (Sandbox Code Playgroud) 我有一个使用BouncyCastle作为安全提供程序的应用程序,但我想切换到直接使用OpenSSL的其他应用程序(Conscrypt)。我遇到的问题是,我正在使用BouncyCastle提供的KeyGenerator中的ECDH“密钥”,但在我的其他库中没有类似的KeyGenerator。
为了比较两者,我将使用下面的输入使用两种方法对点进行解码:
添加了换行符以提高可读性
BADX_GAXp03z_5p05O1-op61KJAl4j9U2sBnAnJ4p_6GSAIyFGU3lM
oC4aIXw_2qlTnplykArgjvwCWw-2g6L44
Run Code Online (Sandbox Code Playgroud)
使用BouncyCastle方法-
public org.bouncycastle.jce.interfaces.ECPublicKey loadECPublicKeyBC(String encodedPublicKey) throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeySpecException, IOException {
Base64.Decoder base64Decoder = Base64.getUrlDecoder();
byte[] decodedPublicKey = base64Decoder.decode(encodedPublicKey);
KeyFactory keyFactory = KeyFactory.getInstance("ECDH", "BC");
ECParameterSpec ecParameterSpec = ECUtil.getECParameterSpec(openSSLProvider, "prime256v1");
ECPoint ecPoint = ECUtil.decodePoint(decodedPublicKey, ecParameterSpec.getCurve());
ECPublicKeySpec pubSpec = new ECPublicKeySpec(ecPoint, ecParameterSpec);
org.bouncycastle.jce.interfaces.ECPublicKey ecPublicKey = (org.bouncycastle.jce.interfaces.ECPublicKey)keyFactory.generatePublic(pubSpec);
return ecPublicKey;
}
Run Code Online (Sandbox Code Playgroud)
在getAlgorithm返回的EC。在getFormat返回的X.509。
此getEncoded值是-
[48,-126,1,51,48,-127,-20,6,7,42,-122,72,-50,61,2,1,48,
-127,-32,2,1,1,48,44,6,7,42,-122,72,-50,61,1,1,2,33,0,
-1,-1,-1,-1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,48,68,4,32,-1,-1,-1,-1,0,0,0,1,
0,0,0,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-4,4,32,90,-58,53,-40,-86,58,-109,-25,-77,-21,-67,85,
118,-104,-122,-68,101,29,6,-80,-52,83,-80,-10,59,-50,60,
62,39,-46,96,75,4,65,4,107,23,-47,-14,-31,44,66,71,-8,-68,
-26,-27,99,-92,64,-14,119,3,125,-127,45,-21,51,-96,-12,
-95,57,69,-40,-104,-62,-106,79,-29,66,-30,-2,26,127,-101,
-114,-25,-21,74,124,15,-98,22,43,-50,51,87,107,49,94,-50,
-53,-74,64,104,55,-65,81,-11,2,33,0,-1,-1,-1,-1,0,0,0,0,-1,
-1,-1,-1,-1,-1,-1,-1,-68,-26,-6,-83,-89,23,-98,-124,-13,
-71,-54,-62,-4,99,37,81,2,1,1,3,66,0,4,0,-41,-4,96,23,-89,
77,-13,-1,-102,116,-28,-19,126,-94,-98,-75,40,-112,37,-30,
63,84,-38,-64,103,2,114,120,-89,-2,-122,72,2,50,20,101,55, …Run Code Online (Sandbox Code Playgroud)