我目前正在使用C#进行AES实现.加密方法有两个参数:字符串和密码.我正在提供提供的字符串并将其转换为字节数组,因此我可以稍后使用它将数据写入流中BinaryWriter.
问题是,当我使用Convert.FromBase64String(string)我得到FormatException: Invalid length.,当我用Encoding.UTF8.GetBytes(string)我的解密方法抛出的和无效的PKCS7.Padding例外.
在过去的几天里,我一直在努力解决这个问题.我已经在stackoverflow.com和其他网站上阅读了几乎无限的问题,但我仍然不知道什么是最可靠的方法来解决这个问题.
将在此程序中使用的字符串仅限于句子(例如"Something to encrypt.")和数字(例如"12345").
提前谢谢,这是我现在的代码:
public class AESProvider {
public byte[] EncryptStringToBytes_Aes(string plainText, string Key)
{
// Check arguments.
if (plainText == null || plainText.Length <= 0)
throw new ArgumentNullException("plainText");
if (Key == null || Key.Length <= 0)
throw new ArgumentNullException("Key");
byte[] plainTextInBytes = Convert.FromBase64String(plainText);
byte[] encrypted;
//Create an Aes object
//with the specified key and IV.
using (Aes aesAlg = Aes.Create())
{
aesAlg.GenerateIV();
byte[] IV = aesAlg.IV; …Run Code Online (Sandbox Code Playgroud) 我正在开发一个统一的2D游戏.游戏中的一个功能是使用鼠标左键单击射击弹丸.释放左击后,射弹会被一定量的力量击打,这取决于玩家持续左击的时间.
问题是,有时当我发布左键单击时,游戏似乎没有检测到它,并且代码的发布部分在我再次单击并释放之前不会被执行.我可能听起来不是一个大问题,但输入可靠性将在这个游戏中发挥重要作用.
那么,有没有办法让鼠标输入更加可靠?我已经尝试过使用Input.GetMouseButtonDown和不同类型的条件以使其更可靠,但它还没有成功.先感谢您!
这是我正在使用的代码:
using UnityEngine;
using System.Collections;
public class ShootPlasma : MonoBehaviour {
//prefab
public Transform bulletPrefab;
//Reloading variables:
public int numberOfBullets;
private int numberOfBulletsRecord;
private bool canShoot=true;
public float timeToReload;
private float timeToReloadRecord;
//direction and bullet Speed variables:
Transform sightPosition;
public Vector3 SpawnRiseVector;
private Vector2 direction;
public float bulletBoost;
private float bulletBoostRecord;
public float MAX_BOOST;
//Arrow Guide
public Transform aimingArrow;
//Helper variables;
private CharacterController2D charControllerScript;
void Start () {
timeToReloadRecord = timeToReload;
numberOfBulletsRecord = numberOfBullets;
charControllerScript = transform.parent.GetComponent<CharacterController2D> …Run Code Online (Sandbox Code Playgroud)