GetRandomFileName and GetTempFileName

T

Tony Johansson

Hi!

I just wonder if anyone has any good experience when it's good to use
GetRandomFileName instead of
GetTempFileName when using the Path class.

//Tony
 
P

Peter Duniho

Tony said:
Hi!

I just wonder if anyone has any good experience when it's good to use
GetRandomFileName instead of
GetTempFileName when using the Path class.

Seems to me the docs are pretty clear on the topic: use the former when
you require the security of a truly "cryptographically strong" random
filename.

More specifically, GetTempFileName() uses a fairly simple and
predictable algorithm for generating filenames. That could be an avenue
of attack for some malicious code that is trying to find a specific
temporary file generated, perhaps by some other process, etc.

Not that using GetRandomFileName() will in and of itself provide
security. But it's one piece of a larger security puzzle.

In general, if you don't know why you should use GetRandomFileName(),
then you probably don't need to.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top