Похожие чаты

Im looking into the source code of dotnet core and

im kinda confused with the code, i was curious to see if the return type byte[] is pinned or not

why? because im auditing my code and i want to know if the garbage collector would relocate it even if i manually pin this byte[] variable after it returns.

but why? because im storing fucking passwords and i need to retrieve them, and i dont want this fucking thing laying around in-memory even after i use it

so, the main question, would this code be safe? (by which i mean, could the garbage collector relocate the bytes and fucking screw me over by leaving a copy of the data in-memory? btw yes im aware SecureString is deprecated. No, i cannot ignore it, they are forcing me to use it):

private SecureString SecureStringFromArray(byte[] secretBytes)
{
var secureString = new SecureString();
char[] secretChars = new char[Encoding.UTF8.GetCharCount(secretBytes)];
GCHandle tempHandle = GCHandle.Alloc(secretChars, GCHandleType.Pinned);

// see https://referencesource.microsoft.com/#mscorlib/system/text/encoding.cs,1234
Encoding.UTF8.GetChars(secretBytes, 0, secretBytes.Length, secretChars, 0);
foreach (var singleCharacter in secretChars)
{
secureString.AppendChar(singleCharacter);
}
// free the temporary array
Array.Clear(secretChars, 0, secretChars.Length);
tempHandle.Free();
return secureString;
}

2 ответов

12 просмотров

why not clear secretBytes too before returning?

jeff-lemon Автор вопроса
Wizou
why not clear secretBytes too before returning?

you probably didnt see that Array.Clear being called

Похожие вопросы

Обсуждают сегодня

я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
в сях есть множество как в питоне? для удаление дубликатов
Linus
25
Hi everyone, long time no see! 🐼 recently i want to update our Ergo Eco-System map, can everyone help to find out, which to delete and other new to add in? list it, that i can...
HEROKOO
13
This topic is discussed al lot. Please use the search function for the answers. The same question pops up every two weeks. First check this video https://www.youtube.com/watch...
Enrico
2
зеленые ноты вижу, а коричневые?
οἰφέω σκάπτω
19
If arrr gets implemented on cake wallet. Would that mean arrr/xmr swaps possible in cake wallet like atomic swaps on komodowallet ?
Keks Meister 🏴‍☠️
22
читать файл максимально быстро? странный вопрос))
zamtmn
53
Yeh scammer hai kya ? 🙄 mujhre bhi solana invest ke liye bol re thi kal
Amit
18
30 BCH videos in Hausa Language successfully delivered. In December 2023, I created a Flipstarter to produce Bitcoin Cash videos in the Hausa language for greater outreach an...
Munnir
9
Я хочу запустить свой проект в тг. Что-то между пирамидой и майнилкой. Еще подобного ничего не было. Уникальная идея. Нужен именно не бот, а приложение. С ввод, выводом тон...
Павел А.
6
Карта сайта