1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#Creates a new self-signed certificate #$cert = New-SelfSignedCertificate -DnsName jesusninoc -CertStoreLocation "Cert:\CurrentUser\My" -KeyUsage KeyEncipherment,DataEncipherment, KeyAgreement -Type DocumentEncryptionCert -KeyExportPolicy ExportableEncrypted $cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where-Object {$_.Subject -eq "CN=jesusninoc"} | Select-Object -First 1 # Función para cifrar el tiempo (timestamp) utilizando el certificado function CifrarTimestampConCertificado { param( [string]$timestamp, [System.Security.Cryptography.X509Certificates.X509Certificate2]$cert ) # Cifrar el timestamp utilizando el certificado $timestampCifrado = $timestamp | Protect-CmsMessage -To $cert # Retornar el timestamp cifrado return $timestampCifrado } # Función para descifrar el tiempo (timestamp) utilizando el certificado function DescifrarTimestampConCertificado { param( [string]$timestampCifrado, [System.Security.Cryptography.X509Certificates.X509Certificate2]$cert ) # Descifrar el timestamp utilizando el certificado $timestampDescifrado = $timestampCifrado | Unprotect-CmsMessage # Retornar el timestamp descifrado return $timestampDescifrado } # Simular el proceso de timestamping $timestamp = Get-Date $timestampString = $timestamp.ToString("yyyy-MM-dd HH:mm:ss") Write-Host "Timestamp original: $timestampString" # Cifrar el timestamp utilizando el certificado $timestampCifrado = CifrarTimestampConCertificado -timestamp $timestampString -cert $cert Write-Host "Timestamp cifrado: $timestampCifrado" # Descifrar el timestamp utilizando el certificado $timestampDescifrado = DescifrarTimestampConCertificado -timestampCifrado $timestampCifrado -cert $cert Write-Host "Timestamp descifrado: $timestampDescifrado" |