public EncryptorService(IOptions <ThumbprintCertificateInfo> certificateInfo) { if (certificateInfo is null || certificateInfo.Value is null) { throw new ArgumentNullException($"Parametr {nameof(certificateInfo)} can not be null"); } var certificate = CertificateExtractor.FindCertificate(certificateInfo.Value); if (certificate is null) { throw new ArgumentNullException($"Can not find certificate {JsonConvert.SerializeObject(certificateInfo.Value)}"); } _rsaEncryptor = new RsaEncryptor(certificate); }
public void SignDataTest() { var str = "你好,中国!"; var rsaEncrypter = new RsaEncryptor(PublicKey, PrivateKey); var signed = rsaEncrypter.SignData(str); Assert.True(rsaEncrypter.VerifyData(str, signed)); var rsa2Encrypter = new RsaEncryptor(PublicKey, PrivateKey); rsa2Encrypter.SetHashAlg("RSA2"); var signed2 = rsa2Encrypter.SignData(str); Assert.True(rsa2Encrypter.VerifyData(str, signed2)); Assert.Equal(signed, signed2); }
public void TrimKey_Test() { var keyPair = RsaUtil.GenerateFormatKeyPair(); var trimedPublicKey = RsaUtil.TrimKey(keyPair.PublicKey); var trimedPrivateKey = RsaUtil.TrimKey(keyPair.PrivateKey); Assert.Contains("-", keyPair.PublicKey); Assert.Contains("-", keyPair.PrivateKey); Assert.DoesNotContain("-", trimedPublicKey); Assert.DoesNotContain("-", trimedPrivateKey); var rsaEncryptor = new RsaEncryptor(trimedPublicKey, trimedPrivateKey); var encrypted1 = rsaEncryptor.Encrypt("china"); var decrypted1 = rsaEncryptor.Decrypt(encrypted1); Assert.Equal("china", decrypted1); }
public static IEncryptor GetEncryptor(DisplayMonkeyEntities _db) // 1.4.0 { EncryptionMethods encryptionMethod = EncryptionMethods.RsaContainer; IEncryptor encryptor = null; Setting s = Setting.GetSetting(_db, Keys.EncryptionMethod); if (s != null) { encryptionMethod = (EncryptionMethods)s.IntValuePositive; } switch (encryptionMethod) { case EncryptionMethods.RsaContainer: encryptor = new RsaEncryptor(); break; case EncryptionMethods.Aes: encryptor = new AesEncryptor(); s = Setting.GetSetting(_db, Keys.EncryptionIV); if (s != null && s.RawValue != null) { (encryptor as AesEncryptor).IV = s.RawValue; } else { Setting.SaveSetting(_db, Keys.EncryptionIV, (encryptor as AesEncryptor).IV); } s = Setting.GetSetting(_db, Keys.EncryptionKey); if (s != null && s.RawValue != null) { (encryptor as AesEncryptor).Key = s.RawValue; } else { Setting.SaveSetting(_db, Keys.EncryptionKey, (encryptor as AesEncryptor).Key); } break; } return(encryptor); }
private static void CreateDependencies(string guestControllerHostUrl, string guestControllerSpoofedIpAddress, string mixApiHostUrl, string oneIdClientId, string mixClientToken, string clientVersion, ICoroutineManager coroutineManager, IKeychain keychain, AbstractLogger logger, string localStorageDirPath, string languageCode, out ISessionLogin sessionLogin, out ISessionRegister sessionRegister, out ISessionRestorer sessionRestorer, out ISessionReuser sessionReuser, out IOfflineSessionCreator offlineSessionCreator) { SystemStopwatchFactory systemStopwatchFactory = new SystemStopwatchFactory(); SystemWwwFactory wwwFactory = new SystemWwwFactory(); WwwCallFactory wwwCallFactory = new WwwCallFactory(logger, coroutineManager, systemStopwatchFactory, wwwFactory); FileSystem fileSystem = new FileSystem(); DatabaseDirectoryCreator databaseDirectoryCreator = new DatabaseDirectoryCreator(fileSystem, localStorageDirPath); DocumentCollectionFactory documentCollectionFactory = new DocumentCollectionFactory(); string sdkDatabasesDirectory = databaseDirectoryCreator.GetSdkDatabasesDirectory(); DatabaseCorruptionHandler databaseCorruptionHandler = new DatabaseCorruptionHandler(logger, fileSystem, sdkDatabasesDirectory); SystemRandom random = new SystemRandom(); SystemEpochTime epochTime = new SystemEpochTime(); Database database = new Database(keychain.LocalStorageKey, random, epochTime, databaseDirectoryCreator, documentCollectionFactory, databaseCorruptionHandler); MixWebCallQueue webCallQueue = new MixWebCallQueue(); MixSessionStartWebCallEncryptor sessionStartEncryptor = new MixSessionStartWebCallEncryptor(); MixWebCallFactoryFactory mixWebCallFactoryFactory = new MixWebCallFactoryFactory(logger, mixApiHostUrl, mixClientToken, wwwCallFactory, webCallQueue, epochTime, database); NotificationDispatcher notificationDispatcher = new NotificationDispatcher(); NotificationQueue notificationQueue = new NotificationQueue(notificationDispatcher); SessionStatus sessionStatus = new SessionStatus(isPaused: true); NoOpSessionRefresher sessionRefresher = new NoOpSessionRefresher(); JsonWebCallEncryptor webCallEncryptor = new JsonWebCallEncryptor(); IMixWebCallFactory webCallFactory = mixWebCallFactoryFactory.Create(webCallEncryptor, string.Empty, string.Empty, sessionRefresher); RsaEncryptor rsaEncryptor = new RsaEncryptor(); MixEncryptor encryptor = new MixEncryptor(); MixWebCallEncryptorFactory webCallEncryptorFactory = new MixWebCallEncryptorFactory(encryptor); SessionRefresherFactory sessionRefresherFactory = new SessionRefresherFactory(webCallQueue); MixSessionStarter mixSessionStarter = new MixSessionStarter(logger, rsaEncryptor, database, webCallEncryptorFactory, sessionStartEncryptor, mixWebCallFactoryFactory, keychain, coroutineManager, sessionRefresherFactory); IStopwatch pollCountdownStopwatch = systemStopwatchFactory.Create(); GuestControllerClientFactory guestControllerClientFactory = new GuestControllerClientFactory(wwwCallFactory, guestControllerSpoofedIpAddress, database, guestControllerHostUrl, oneIdClientId, logger); SessionFactory sessionFactory = new SessionFactory(logger, coroutineManager, pollCountdownStopwatch, epochTime, databaseCorruptionHandler, notificationQueue, notificationDispatcher, sessionStatus, mixWebCallFactoryFactory, webCallEncryptorFactory, mixSessionStarter, keychain, sessionRefresherFactory, guestControllerClientFactory, random, encryptor, fileSystem, wwwCallFactory, localStorageDirPath, clientVersion, databaseDirectoryCreator, documentCollectionFactory, database); AgeBandBuilder ageBandBuilder = new AgeBandBuilder(logger, webCallFactory); Disney.Mix.SDK.Internal.RegistrationConfigurationGetter registrationConfigurationGetter = new Disney.Mix.SDK.Internal.RegistrationConfigurationGetter(logger, guestControllerClientFactory, ageBandBuilder); LegalMarketingErrorsBuilder legalMarketingErrorsBuilder = new LegalMarketingErrorsBuilder(registrationConfigurationGetter, languageCode, epochTime); sessionLogin = new SessionLogin(logger, guestControllerClientFactory, mixSessionStarter, database, legalMarketingErrorsBuilder, sessionFactory); sessionRegister = new SessionRegister(logger, guestControllerClientFactory, database, mixSessionStarter, sessionFactory); sessionRestorer = new SessionRestorer(logger, guestControllerClientFactory, database, sessionFactory); sessionReuser = new SessionReuser(logger, database, mixSessionStarter, sessionFactory); offlineSessionCreator = new OfflineSessionCreator(logger, sessionFactory, database); }
public void Pkcs8_Pkcs1_Conver_Test() { var keyPair = RsaUtil.GenerateKeyPair(); var rsaEncryptor1 = new RsaEncryptor(keyPair.PublicKey, keyPair.PrivateKey); var pkcs8Key = RsaUtil.Pkcs1ToPkcs8(keyPair.PrivateKey); var rsaEncryptor2 = new RsaEncryptor(keyPair.PublicKey, pkcs8Key); var d1 = rsaEncryptor1.Encrypt("123456"); var d2 = rsaEncryptor2.Encrypt("123456"); //Assert.Equal(d1, d2); var d3 = rsaEncryptor1.Decrypt(d1); Assert.Equal("123456", d3); var d4 = rsaEncryptor2.Decrypt(d2); var pkcs1Key = RsaUtil.Pkcs8ToPkcs1(pkcs8Key); Assert.Equal(keyPair.PrivateKey, pkcs1Key); }
public void RSA2SignDataTest() { var str = "你好,中国!"; var rsaEncrypter = new RsaEncryptor(RSA2PrivateKey, RSA2PublicKey); rsaEncrypter.SetHashAlg("RSA2"); var signed = rsaEncrypter.SignData(str); Assert.True(rsaEncrypter.VerifyData(str, signed)); var rsa2Encrypter = new RsaEncryptor(RSA2PrivateKey, RSA2PublicKey); rsa2Encrypter.SetHashAlg("RSA2"); var signed2 = rsa2Encrypter.SignData(str); Assert.True(rsa2Encrypter.VerifyData(str, signed2)); var sign = rsa2Encrypter.SignData("a=123"); var expected = @"Cm6L1nwSKn4h1V1CORIYFDo2lPT4gLQtSy9+ZDKQUlq/xyB4B23jmoMy8ecPwi7e8U9RC528T5aRL6ksBFommyGLaTGjrucABjF42wL+lG3Lks7xZ5mhiV4BbCzRfU7DGuI5c6f9xvdpFumT/mQdRZtIFOUCdQCx/oDTSJQ3vNZYoFY02lfnwhMQziQ50YWqodOy1E8JeWZ3R3dovDj1NyHF5OExpuWa0OyWIkuI279waHm92pyet7tb5jzS0lTpq5rSrhG0wb2qhFYedQO87+c6Yusrhghvql4XJ2zEcA9vQvw3nepiuBG9DBm0A2B8GPUlG2gsJHClflEIZQ806A=="; Assert.Equal(expected, sign); }
public void Encrypt_should_throw_NotImplementedException() { var sut = new RsaEncryptor(null); Assert.Throws <NotImplementedException>(() => sut.Encrypt(null, null)); }
/// <summary> /// 签名 /// </summary> public string Sign() { RsaEncryptor rsaEncryptor = new RsaEncryptor().LoadPrivateKey(_key.GetKey()); return(rsaEncryptor.SignData(_builder.Result(true))); }
public RsaSenderVIewModel() { Encrypt = new DelegateCommand(EncryptMessage); rsaEncryptor = new RsaEncryptor(); }
public RsaEncryptorShould() { _encryptor = new RsaEncryptor(); }