Unable to obtain public key for StrongNameKeyPair

time to read 2 min | 396 words

This problem came up a few time in the Rhino Mocks mailing list. The issue is that you can no longer sign assemblies (which is something that Rhino Mocks does on the fly).

There are several things that you can do to fix this issue:

  • Use "sn.exe -m n" to set the key containers to user based.
  • use "sn.exe -c" to reset the CSP.

Most often the issue is file permission one. And the troublesome directory is (drum roll): "C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA"

The defualt permission for this directory are:

cacls MachineKeys
MachineKeys Everyone:(special access:)
        READ_CONTROL
        SYNCHRONIZE
        FILE_GENERIC_READ
        FILE_GENERIC_WRITE
        FILE_READ_DATA
        FILE_WRITE_DATA
        FILE_APPEND_DATA
        FILE_READ_EA
        FILE_WRITE_EA
        FILE_READ_ATTRIBUTES
        FILE_WRITE_ATTRIBUTES

     BUILTIN\Administrators:F

Administrators has full control, everyone has had read/write access, but not delete access.