電子メールアドレスや数値などの文字列値を暗号化および復号化する必要がありますが、暗号化された文字列に '/'私はURLでそれを使用していて、セパレータには '/'を使用して値を取得しています。暗号化/復号化方法に暗号化された文字列に '/'が含まれていない
あなただけのURLを渡すためにそれをやっている場合はstring passPhrase = "[email protected]"; // can be any string
string saltValue = "[email protected]"; // can be any string
string hashAlgorithm = "SHA1"; // can be "MD5"
int passwordIterations = 2; // can be any number
string initVector = "@1B2c3D4e5F6g7H8"; // must be 16 bytes
int keySize = 256; // can be 192 or 128
public string Encrypt(string plainText)
{
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase,saltValueBytes,hashAlgorithm,passwordIterations);
byte[] keyBytes = password.GetBytes(keySize/8);
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes,initVectorBytes);
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream,encryptor,CryptoStreamMode.Write);
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
byte[] cipherTextBytes = memoryStream.ToArray();
memoryStream.Close();
cryptoStream.Close();
string cipherText = Convert.ToBase64String(cipherTextBytes);
return cipherText;
}
「/」を他の文字に置き換えるのはどうでしょうか? –
URLで使用している場合、 'UrlEncode'と' UrlDecode'は動作しませんか? – Corak
このリンクを試す1. [Link1](http://stackoverflow.com/questions/10168240/encrypting-decrypting-a-string-in-c-sharp)2. [Link2](http://stackoverflow.com/質問/ 202011 /暗号化 - 解読 - 文字列 - ネット)ありがとうAbiruban – Niventh