我使用以下方法加密我的项目中的connectionstrings部分(我app.config在我的WinForms项目中使用Code First EF):
public static void EncryptConfig(string exeConfigName)
{
var config = ConfigurationManager.OpenExeConfiguration(exeConfigName);
var section = config.GetSection("connectionStrings") as ConnectionStringsSection;
if (section != null || !section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
config.Save();
}
}
Run Code Online (Sandbox Code Playgroud)
我也使用以下方法解密该connectionstrings部分:
public static void DecryptConfig(string exeConfigName)
{
var config = ConfigurationManager.OpenExeConfiguration(exeConfigName);
var section = config.GetSection("connectionStrings") as ConnectionStringsSection;
if (section != null && section.SectionInformation.IsProtected)
section.SectionInformation.UnprotectSection();
}
Run Code Online (Sandbox Code Playgroud)
这个方法适用于我的机器,但当我将我的应用程序部署到另一台机器时,我得到以下异常:
System.Configuration.ConfigurationErrorsException:无法使用提供程序'DataProtectionConfigurationProvider'解密.来自提供程序的错误消息:密钥无法在指定状态下使用.(来自HRESULT的异常:0x8009000B)(D:\ l4test\Level4UI.exe.config第82行)---> System.Runtime.InteropServices.COMException:密钥在指定状态下无效.(来自HRESULT的异常:0x8009000B)
在System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode,IntPtr errorInfo)
在System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
在System.Configuration.DpapiProtectedConfigurationProvider.DecryptText(String encText)
在System.Configuration.DpapiProtectedConfigurationProvider.Decrypt(XmlNode encryptedNode)
在System.Configuration.ProtectedConfigurationSection.DecryptSection(String encryptedXml,ProtectedConfigurationProvider provider)
在System.Configuration.Internal.InternalConfigHost.System.Configuration.Internal.IInternalConfigHost.DecryptSection(String …
我想从我的服务器下载加密文件,解密并在本地保存.我想解密文件并在下载时将其写入本地,而不是等待下载完成,解密,然后将解密文件放在锚标记中.我想这样做的主要原因是,对于大文件,浏览器不必在内存中存储数百兆字节或几千兆字节.
我试图part444.txt用消息解密文件():
y2EdLtmNQsZkvwwf8jf3fM6c1thfzF0sQfblayGIBik=
Run Code Online (Sandbox Code Playgroud)
这是在CBC模式下128位AES下的base64编码加密文本.它没有填充.IV是加密文本的前16个字节,密钥是h4ckth1sk3yp4d16.
我知道人们从Base64的问题中收到了错误的幻数错误,但现在我得到了"错误读取输入文件"而不知道从哪里开始.
我试过了:
openssl enc -base64 -d part444.txt | openssl aes-128-cbc -d -k h4ckth1sk3yp4d16
Run Code Online (Sandbox Code Playgroud)
为什么我遇到错误"坏幻数"和"错误读取输入文件"?
我可以毫无困难地在AV播放器中播放普通的HLS视频.但是如何播放AES-128加密的HLS视频?
在多线程Java应用程序中,我们使用AES-256对磁盘进行文件加密和解密.请注意,多个线程可以同时调用不同文件的加密和解密方法.
加密:
Cipher encrypter = Cipher.getInstance(algorithm, new BouncyCastleProvider());
IvParameterSpec ivSpec = getIvParamSpec(encrypter.getBlockSize());
encrypter.init(Cipher.ENCRYPT_MODE, key, ivSpec);
//..encrypt the data
Run Code Online (Sandbox Code Playgroud)
解密:
Cipher decrypter = Cipher.getInstance(algorithm, new BouncyCastleProvider());
IvParameterSpec ivSpec = readIvParamSpec(decrypter.getBlockSize(), is);
decrypter.init(Cipher.DECRYPT_MODE, key, ivSpec);
//.. decrypt the data
Run Code Online (Sandbox Code Playgroud)
根据我们的理解,最好使用随机IV进行加密而不是静态/固定IV.为此,我们使用SecureRandom API生成IV.随机IV在开始时保存在加密文件中.
SecureRandom random = new SecureRandom();
byte[] iv = new byte[ivSizeBytes];
random.nextBytes(iv);
new IvParameterSpec(iv);
Run Code Online (Sandbox Code Playgroud)
我的问题是,因为我使用随机IV进行每次加密,我是否需要为所有调用调用Cipher.getInstance()和Cipher.Init()?为了提高性能,这些只能在类初始化期间调用一次,然后重用单个密码实例来加密和解密数据吗?
提前致谢!
您好我在那里尝试使用信号协议进行客户端消息交换(仅用于测试).但我对proccessPreKey有困难.
这是测试代码
<script src="javascripts/libsignal-protocol.js"></script>
<script src="javascripts/InMemorySignalProtocolStore.js"></script>
<script>
var KeyHelperUser1 = libsignal.KeyHelper;
var KeyHelperUser2 = libsignal.KeyHelper;
var registrationId_User1 = KeyHelperUser1.generateRegistrationId();
var registrationId_User2 = KeyHelperUser2.generateRegistrationId();
// Store registrationId somewhere durable and safe.
var identityKeyPair_User1, identityKeyPair_User2;
var SignedPreKey_User1, SignedPreKey_User2;
// Test Store
var store_User1 = new SignalProtocolStore();
var store_User2 = new SignalProtocolStore();
var PreKey_User1, PreKey_User2;
// Build the session
var address_User1 = new libsignal.SignalProtocolAddress(1002, 0);
var address_User2 = new libsignal.SignalProtocolAddress(1001, 0);
var sessionBuilder_User1 = new libsignal.SessionBuilder(store_User1, address_User1);
var sessionBuilder_User2 = new libsignal.SessionBuilder(store_User2, address_User2); …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试将加密的HLS流下载到iOS设备.iOS 10似乎支持开箱即用(请参阅https://developer.apple.com/videos/play/wwdc2016/504),但我无法让它工作.我基本上是用AssetPersistenceManager来自苹果的示例代码(https://developer.apple.com/library/content/samplecode/HLSCatalog/Introduction/Intro.html),它调用makeAssetDownloadTask的AVAssetDownloadURLSession.它在在线模式下工作正常,但从存储的文件播放资源时播放失败.
现在,WWDC视频表明您应该使用AVAssetResourceLoaderDelegate提供脱机加密密钥.由于HTTP和HTTPS似乎不被支持AVAssetResourceLoader(见例如不工作的设备AVAssetResourceLoaderDelegate方法),我尝试使用该键URI自定义方案,并提供在本地AES密钥shouldWaitForLoadingOfRequestedResource的AVAssetResourceLoaderDelegate.这里也适用于在线流媒体,但无论我是使用远程密钥URL还是使用本地密钥覆盖它,AVPlayer始终无法离线播放AVAsset.
有没有人有下载加密HLS的经验,或者有一个关于如何提供加密密钥以便离线播放本地加密AVURLAsset的工作示例?
我正在使用的示例HSL文件位于:http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel-aes.ism/.m3u8
我想使用AES加密和解密来自SD卡的文件.为了做到这一点,我们总是需要一个种子(通常是一个由用户作为密码插入的字符串):
public static byte[] generateKey(String password) throws Exception{
byte[] keyStart = password.getBytes("UTF-8");
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG", "Crypto");
sr.setSeed(keyStart);
kgen.init(128, sr);
SecretKey skey = kgen.generateKey();
return skey.getEncoded();
}
Run Code Online (Sandbox Code Playgroud)
我想跳过这一步(用户插入密码),并且要求用户通过指纹传感器进行身份验证,然后启动加密过程!
我想知道是否有一种方法可以为触摸指纹传感器的每个不同手指获取一个唯一键,可以用作SEED来创建SecretKey!
我在github上阅读了关于SO和相关样本的一些问题,但我仍然找不到办法.
清除问题:我已经完成了AES本身的实现并且完全没问题,我只需要在身份验证后找到一种从指纹传感器获取唯一键的方法.
encryption android fingerprint secret-key android-fingerprint-api
我有以下使用Bouncy Castle for C#创建加密私钥的方法:
public string GetPrivateKey(AsymmetricCipherKeyPair keyPair, string password)
{
var generator = new Pkcs8Generator(keyPair.Private, Pkcs8Generator.PbeSha1_3DES);
generator.IterationCount = 4;
generator.Password = password.ToCharArray();
var pem = generator.Generate();
TextWriter textWriter = new StringWriter();
PemWriter pemWriter = new PemWriter(textWriter);
pemWriter.WriteObject(pem);
pemWriter.Writer.Flush();
string privateKey = textWriter.ToString();
return privateKey;
}
Run Code Online (Sandbox Code Playgroud)
看起来像这样:
-----BEGIN ENCRYPTED PRIVATE KEY-----
...
-----END ENCRYPTED PRIVATE KEY-----
Run Code Online (Sandbox Code Playgroud)
我不知道如何在Decrypt方法中使用用于加密私钥的密码。现在,在不知道如何使用he来“解密”我的私钥password的情况下,我得到了以下异常:
Org.BouncyCastle.OpenSsl.PemException:创建ENCRYPTED私钥时出现问题:System.NullReferenceException:对象引用未设置为对象的实例。在Org.BouncyCastle.OpenSsl.PemReader.ReadPrivateKey(PemObject pemObject)
这是Decrypt方法的代码:
public string Decrypt(string base64Input, string privateKey, string password)
{
var bytesToDecrypt = Convert.FromBase64String(base64Input);
//get a stream from the …Run Code Online (Sandbox Code Playgroud) encryption ×10
aes ×3
avplayer ×2
c# ×2
cryptography ×2
ios ×2
javascript ×2
android ×1
app-config ×1
bash ×1
bouncycastle ×1
download ×1
expo ×1
file-storage ×1
fingerprint ×1
iphone ×1
java ×1
offline ×1
openssl ×1
pem ×1
private-key ×1
react-native ×1
secret-key ×1
winforms ×1