if
(
strspn
(
$text
,
chr
(
$pad
),
strlen
(
$text
) -
$pad
) !=
$pad
) {
return
false;
}
return
substr
(
$text
, 0, - 1 *
$pad
);
}
}
//使用
include
('STD3Des.class.php');
$key
='abcdefgh';
$iv
='abcdefgh';
$msg
='test string';
$des
=
new
STD3Des(
base64_encode
(
$key
),
base64_encode
(
$iv
));
$rs1
=
$des
->encrypt(
$msg
);
echo
$rs1
.'<br />';
$rs2
=
$des
->decrypt(
$rs1
);
echo
$rs2
;
.net 版本
代码如下:
sealed
public
class
CryptoHelper
{
/// <summary>
/// Encrypts the specified input.
/// </summary>
/// <param name="input">The input.</param>
/// <param name="key">key</param>
/// <param name="iv">iv</param>
/// <returns></returns>
public
static
string EncryptDes(string input, byte[] key, byte[] iv)
{
if
(input == null || input.Length == 0)
return
String.
Empty
;
DESCryptoServiceProvider des =
new
DESCryptoServiceProvider();
MemoryStream ms = null;
CryptoStream encStream = null;
StreamWriter sw = null;
string result = String.
Empty
;