@@ -26,7 +26,7 @@ namespace Microsoft.WindowsAzure.Commands.Utilities.Common.Authentication
26
26
/// </summary>
27
27
public class ProtectedFileTokenCache : TokenCache
28
28
{
29
- private static readonly string CacheFileName = Path . Combine ( AzurePowerShell . ProfileDirectory , "TokenCache.dat" ) ;
29
+ public static readonly string CacheFileName = Path . Combine ( AzurePowerShell . ProfileDirectory , "TokenCache.dat" ) ;
30
30
31
31
private static readonly object fileLock = new object ( ) ;
32
32
@@ -54,7 +54,14 @@ private ProtectedFileTokenCache()
54
54
var existingData = ProfileClient . DataStore . ReadFileAsBytes ( CacheFileName ) ;
55
55
if ( existingData != null )
56
56
{
57
- Deserialize ( ProtectedData . Unprotect ( existingData , null , DataProtectionScope . CurrentUser ) ) ;
57
+ try
58
+ {
59
+ Deserialize ( ProtectedData . Unprotect ( existingData , null , DataProtectionScope . CurrentUser ) ) ;
60
+ }
61
+ catch ( CryptographicException )
62
+ {
63
+ ProfileClient . DataStore . DeleteFile ( CacheFileName ) ;
64
+ }
58
65
}
59
66
}
60
67
}
@@ -81,7 +88,14 @@ void BeforeAccessNotification(TokenCacheNotificationArgs args)
81
88
var existingData = ProfileClient . DataStore . ReadFileAsBytes ( CacheFileName ) ;
82
89
if ( existingData != null )
83
90
{
84
- Deserialize ( ProtectedData . Unprotect ( existingData , null , DataProtectionScope . CurrentUser ) ) ;
91
+ try
92
+ {
93
+ Deserialize ( ProtectedData . Unprotect ( existingData , null , DataProtectionScope . CurrentUser ) ) ;
94
+ }
95
+ catch ( CryptographicException )
96
+ {
97
+ ProfileClient . DataStore . DeleteFile ( CacheFileName ) ;
98
+ }
85
99
}
86
100
}
87
101
}
0 commit comments