public T1 GetValue(ILightCertificate certToVerifyData) { if (certToVerifyData == null) { throw new ArgumentNullException( MyNameof.GetLocalVarName(() => certToVerifyData) ); } if (Data == null) { throw new ArgumentNullException( this.MyNameOfProperty(e => e.Data) ); } if (certToVerifyData.Id != Signature.SignerCertificateId) { throw new ArgumentException( certToVerifyData.MyNameOfProperty(e => e.Id) ); } if (!certToVerifyData.VerifyData(this)) { throw new CryptographicException( "Verification failed" ); } return(Deserialize(Data)); }
public SignedData( T1 value, ILightCertificate cert, byte[] pass ) { var dataToSign = Serialize(value); var signedData = cert.SignData(dataToSign, pass); Data = signedData.Data; Signature = signedData.Signature; }
public static SignedData <T1> GetSignedData( T1 value, ILightCertificate cert, byte[] pass ) { var dataToSign = Serialize(value); var signedData = cert.SignData(dataToSign, pass); return(new SignedData <T1>() { Data = signedData.Data, Signature = signedData.Signature }); }
private RegistrationFormValuesWrapper.Step2 Step1(RegistrationFormValuesWrapper.Step1 valuesWrapper) { var entranceService = _context.UnityContainer.Resolve <IEntranceService>(); switch (valuesWrapper.Control1AuthenticationType) { case RegistrationFormValuesWrapper.Step1.Control1AuthenticationTypeValueClassic: { var identifier = long.Parse(valuesWrapper.Control2Identifier); var encrypted = File.ReadAllBytes(valuesWrapper.Control3BackupFile); var password = valuesWrapper.Control4BackupFilePassword; byte[] decryptedKey; try { decryptedKey = entranceService.DecryptKeeperKey(encrypted, identifier, password); } catch (Exception exception) { throw new WrongPasswordException( Resources.RegistrationFormProvider_Step1_Wrong_password_or_WMID_for_kwm_file_, exception); } _identifier = identifier; _decryptedKey = decryptedKey; _lightCertificate = null; } break; case RegistrationFormValuesWrapper.Step1.Control1AuthenticationTypeValueLight: var lightCertificate = (ILightCertificate)valuesWrapper.Control5Certificate; _identifier = lightCertificate.Identifier; _decryptedKey = null; _lightCertificate = lightCertificate; break; default: throw new InvalidOperationException("valuesWrapper.Control1AuthenticationType == " + valuesWrapper.Control1AuthenticationType); } if (entranceService.CheckRegistration(_identifier)) { var identifierValue = _context.UnityContainer.Resolve <IFormattingService>() .FormatIdentifier(_identifier); throw new DuplicateRegistrationException(string.Format(CultureInfo.InvariantCulture, Resources.RegistrationFormProvider_Step1_WMID__0__already_registered_, identifierValue)); } var connectionString = entranceService.SuggestConnectionString(_identifier) ?? Translator.Instance.Translate(ExtensionCatalog.Registration, "<DB-connection is not supported>"); var step2Wrapper = new RegistrationFormValuesWrapper.Step2 { Control5ConnectionString = connectionString }; return(step2Wrapper); }