0

パスワード フィールドを SQL Server データベースに暗号化された形式で保存する必要があり、ユーザーがシステムにログインしている間に復号化する必要があります。暗号化部分は正常に動作しています。しかし、復号化部分で「Base-64 char配列の長さが無効です」という行でエラーが発生しています

byte[] todecode_byte = Convert.FromBase64String(encryptpwd);   

復号化モジュールの。

private string Encryptdata(string password)
{
        string encryptpwd = string.Empty;
        byte[] encode = new byte[password.Length];
        encode = Encoding.UTF8.GetBytes(password);
        encryptpwd = Convert.ToBase64String(encode);
        return encryptpwd;
}

private string Decryptdata(string encryptpwd)
{
        string decryptpwd = string.Empty;
        UTF8Encoding encodepwd = new UTF8Encoding();
        Decoder Decode = encodepwd.GetDecoder();
        byte[] todecode_byte = Convert.FromBase64String(encryptpwd); //here I am getting error as "Invalid length for a Base-64 char array"
        int charCount = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
        char[] decoded_char = new char[charCount];
        Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
        decryptpwd = new String(decoded_char);
        return decryptpwd;
}

入力データ:prabu
暗号化されたデータ:cHJhYnU=

4

3 に答える 3

0

コードが次のようになっているため、エラーが発生します。

    string password = "prabu";
    string encryptdata = Encryptdata(password);
    string decryptdata = Decryptdata(password);
于 2012-09-25T06:41:23.600 に答える