php - 将VBA加密函数转换为PHP

标签 php vba encryption

这是我的第一个问题,希望一切顺利。

我有一个应用程序当前使用 VBA 代码在 MS Access 下的桌面上运行。当用户登录时,我有一个加密密码的功能。这是:

Public Function EncryptEasy(strIn As String) As String

Dim strChr As String
Dim i As Integer
Dim Salt As Long
Salt = 543214321

For i = 1 To Len(strIn)
  strChr = strChr & CStr(Asc( Mid(strIn, i, 1) ) Xor Salt)
Next I

EncryptEasy = strChr

End Function

为了给你一个想法,当我在 VBA 中运行 EncryptEasy("test") 时,它返回: 543214213543214228543214210543214213

我现在正在使用 PHP 设置一个简单的网络应用程序,并希望通过将此函数编码到 PHP 中来利用与我当前使用的相同的加密。我已经尝试过,以下是我的尝试:

function EncryptEasy($strIn) {

$salt = 543214321;
$strChr = Null;
$strLen = strlen($strIn);

  for ($i = 0; $i <= $strLen; $i++) {
      $strChr = $strChr . chr(ord(substr($strIn, $i, 1)) xor $salt);
  }

  return $strChr;

}

然而,这将返回空白。我试过回应这个:

<?php
echo EncryptEasy("test");
?>

没用。

有人能看出我哪里出错了吗?

最佳答案

我不建议创建您的 own algorithm for encrypting ,而是使用 php 提供的内置函数。

虽然这不像您原始代码中的那样加密密码,但使用 password_hash比创建自己的更容易,并验证使用 password_verify()

散列密码:

<?php
    $hashed = password_hash("somePassword", PASSWORD_DEFAULT);
?>

验证密码

<?php
    if(password_verify('somePassword', $hashed))
    {
        echo 'Same'; //goes here
    } else {
        echo 'Not same';
    }
    if(password_verify('somePasswordsss', $hashed))
    {
        echo 'Same'; 
    } else {
        echo 'Not same'; //goes here
    }
?>

关于php - 将VBA加密函数转换为PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45603157/

相关文章:

php mysql选择不同的值

php - 在 macOS 上本地运行 CouchCMS 时路径损坏

php - 如何使用 select st 在 mysql 中同时获取值并继续执行下一个递增 id

vba - 在 VBA 中隐藏用户窗体以便处理数据

php - 你如何在没有多个数据库连接的情况下执行多个 AJAX 请求?

excel - 升序/降序vba excel

Excel VBA : How do I PasteSpecial into same row of Cell location after Cell is changed?

c - Vigenere Cipher - 如何忽略纯文本中的空格(在 C 中)?

ios - 在 iOS 中使用 SecRandomCopyBytes( ) 的随机 256 位 key

android - [Android][加密]声明加密类型时如何避免使用字符串