Created
September 11, 2014 08:37
-
-
Save nedyalkov/a563dd4fb04d21cb91dc to your computer and use it in GitHub Desktop.
SignFile with Sha1 algorithm when using Sha256 certificate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function SignFile($filePath, $timeStampUri, $certThumbprint) | |
{ | |
$x509Store = New-Object -TypeName ([System.Security.Cryptography.X509Certificates.X509Store]) -ArgumentList ([System.Security.Cryptography.X509Certificates.StoreName]::My),([System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser) | |
try | |
{ | |
$x509Store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly) | |
$x509Certificate2Collection = $x509Store.Certificates.Find([System.Security.Cryptography.X509Certificates.X509FindType]::FindByThumbprint, $certThumbprint, $false); | |
if ($x509Certificate2Collection.Count -eq 1) | |
{ | |
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]@($x509Certificate2Collection)[0] | |
# This will force using of SHA1 instead of SHA256 | |
$cert.SignatureAlgorithm.FriendlyName = "" | |
Add-Type -AssemblyName "Microsoft.Build.Tasks.v4.0" | |
echo "Calling SignFile with file $filePath" | |
if(Test-Path $filePath) | |
{ | |
echo "File to be signed exists" | |
} | |
[Microsoft.Build.Tasks.Deployment.ManifestUtilities.SecurityUtilities]::SignFile($cert, $timeStampUri, $filePath) | |
} | |
} | |
finally | |
{ | |
$x509Store.Close(); | |
} | |
} |
Hey @RodrigoDotNet, I'm really sorry, but I didn't notice your comment here.
I'd love to help if you still need my help, of course 😄. My email is miroslav.nedialkov@gmail.com, so just drop me a line.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I need help with this script . Could you help me ?