我需要实现加密的自定义链接模式。我需要使用对称分组密码(AES,3DES,DES,IDEA)。我遇到的问题是,我发现的库/包装器不允许它。
BouncyCastle有那些作为Enum:System.Security.Cryptography
,所以我没有看到 - 我如何使用自己的。 <?php
namespace CockpitBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
/**
* TCTimeCard
*/
class TCTimeCard
{
/**
* @var integer
*/
private $id;
/**
* @var \DateTime
*/
private $startDate;
/**
* @var \DateTime
*/
private $endDate;
/**
* @var \DateTime
*/
private $approvedDate;
/**
* @var \DateTime
*/
private $processedDate;
/**
* @var \DateTime
*/
private $modifiedDate;
/**
* @var string
*/
private $notes;
/**
* @var \CockpitBundle\Entity\TCStatus
*/
private $status;
/**
* @var \CockpitBundle\Entity\Employee
*/
private $employee;
/**
* @var \CockpitBundle\Entity\Employee
*/
private $approvedBy;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $tcslots;
/**
* @var \DateTime
*/
private $periodBegin;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $tcdayslots;
/**
* Constructor
*/
public function __construct()
{
$this->tcslots = new ArrayCollection();
$this->tcdayslots = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/* Removed some of the getters/setters to save scrolling */
/**
* Set employee
*
* @param \CockpitBundle\Entity\Employee $employee
*
* @return TCTimeCard
*/
public function setEmployee(\CockpitBundle\Entity\Employee $employee = null)
{
$this->employee = $employee;
return $this;
}
/**
* Get employee
*
* @return \CockpitBundle\Entity\Employee
*/
public function getEmployee()
{
return $this->employee;
}
/**
* @ORM\PreUpdate
*/
public function updateModifiedDatetime()
{
// Add your code here
}
/**
* Add tcdayslot
*
* @param \CockpitBundle\Entity\TCDaySlot $tcdayslot
*
* @return TCTimeCard
*/
public function addTcdayslot(\CockpitBundle\Entity\TCDaySlot $tcdayslot)
{
$this->tcdayslots[] = $tcdayslot;
return $this;
}
/**
* Remove tcdayslot
*
* @param \CockpitBundle\Entity\TCDaySlot $tcdayslot
*/
public function removeTcdayslot(\CockpitBundle\Entity\TCDaySlot $tcdayslot)
{
$this->tcdayslots->removeElement($tcdayslot);
}
/**
* Get tcdayslots
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getTcdayslots()
{
return $this->tcdayslots;
}
}
似乎也是这样做的。
是否有允许自定义链接模式的.NET库或包装器?
现在我唯一的想法是使用CBC加密每个块,其中IV充满零位并在其上实现我的链接模式,但它似乎不是一个好主意。
答案 0 :(得分:2)
我不知道任何支持链接回调的库,它有点违背大多数加密API的黑盒子。
实现目标的方法是使用 ECB 加密,因为这是&#34;只需将加密算法应用于此数据&#34;。例如,要做CBC:
private byte[] _iv;
private ICryptoTransform _encryptor;
private void EncryptBlock(byte[] input, byte[] output)
{
byte[] buf = (byte[])input.Clone();
for (int i = 0; i < buf.Length; i++)
{
buf[i] ^= _iv[i];
}
_encryptor.TransformBlock(buf, 0, buf.Length, output, 0);
Buffer.BlockCopy(out, 0, _iv, 0, output.Length);
}
(省略了各种错误检查)
鉴于某处,您将事物初始化为
using (Aes aes = Aes.Create())
{
aes.Mode = CipherMode.ECB;
aes.Key = key;
_encryptor = aes.CreateEncryptor();
_decryptor = aes.CreateDecryptor();
}
(等)。