我想我缺少一些关于基于密码的数据加密的基本知识.
破解基于密码哈希的登录身份验证的工具知道在成功登录时找到了正确的密码(或者仍然匹配哈希的备用密码).但是如何使用密码作为源来破解基于文件或流的加密的工具知道何时成功?在我看来,不同的尝试密码会将加密的源流转换为不同的目标字节集,其中特定的密码生成"正确的"字节集.我不明白破解工具如何识别它具有正确的未加密字节集,停止尝试并报告'破解!'.
我很遗憾地问你关于这么多问题的技巧.我有一个关于RSA crypthography的问题.我已经检查了有关此问题的其他主题,但我没有找到任何有用的答案.我希望你能帮助我.
我想读取一个文件,将其包含,然后解密,并将这些解密的字节放在一个新文件中.
我实际上可以: - 获取文件的字节 - 加密它
我有一个例外:javax.crypto.BadPaddingException:数据必须从零开始.
这是我的代码:
package com.bodom.ghosty;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.io.*;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.*;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;
import java.util.Scanner;
public class EncryptionUtil {
private final PrivateKey privateKey;
private final PublicKey publicKey;
/**
* Build an EncryptionUtil object
*
* @param keyPair The KeyPair used for Ghosty
*/
public EncryptionUtil (KeyPair keyPair) {
this.privateKey = keyPair.getPrivate(); …Run Code Online (Sandbox Code Playgroud) 我在C#(VS2012,.NET 4.5)中加密和解密文本时遇到问题.具体来说,当我加密并随后解密字符串时,输出与输入不同.但是,奇怪的是,如果我复制加密输出并将其硬编码为字符串文字,解密就可以了.以下代码示例说明了该问题.我究竟做错了什么?
var key = new Rfc2898DeriveBytes("test password", Encoding.Unicode.GetBytes("test salt"));
var provider = new AesCryptoServiceProvider { Padding = PaddingMode.PKCS7, KeySize = 256 };
var keyBytes = key.GetBytes(provider.KeySize >> 3);
var ivBytes = key.GetBytes(provider.BlockSize >> 3);
var encryptor = provider.CreateEncryptor(keyBytes, ivBytes);
var decryptor = provider.CreateDecryptor(keyBytes, ivBytes);
var testStringBytes = Encoding.Unicode.GetBytes("test string");
var testStringEncrypted = Convert.ToBase64String(encryptor.TransformFinalBlock(testStringBytes, 0, testStringBytes.Length));
//Prove that the encryption has resulted in the following string
Debug.WriteLine(testStringEncrypted == "cc1zurZinx4yxeSB0XDzVziEUNJlFXsLzD2p9TWnxEc="); //Result: True
//Decrypt the encrypted text from a hardcoded string literal …Run Code Online (Sandbox Code Playgroud) 假设有一种加密字符串的方法:
例如,单词FRUIT按以下方式加密:
We append the character $ at the end of the word:
FRUIT$
We then form all the strings by moving the first character at the end:
FRUIT$
RUIT$S
UIT$FR
IT$FRU
T$FRUI
$FRUIT
Then we sort the new strings into alphabetical order:
$FRUIT
FRUIT$
IT$FRU
RUIT$F
T$FRUI
UIT$FR
The encrypted string:
T$UFIR
Run Code Online (Sandbox Code Playgroud)
现在我的问题很明显:如何将给定的字符串解密为原始形式.
我现在已经打了半个星期了,我终于没纸了.
我该怎么做呢?
我发现了什么:
如果我们有加密的最后一步:
$FRUIT
FRUIT$
IT$FRU
RUIT$F
T$FRUI
UIT$FR
Run Code Online (Sandbox Code Playgroud)
我们可以知道原始字符串的第一个和最后一个字符,因为最右边的列是加密字符串本身,最左边的列总是按字母顺序排列.最后一个字符是加密字符串的第一个字符,因为$始终是字母表中的第一个字符,并且它只在字符串中存在一次.然后,如果我们从最右边的列中找到$字符,并在最左边的列中查找同一行上的字符,我们将得到第一个字符.
所以我们对加密字符串T $ UFIR的了解是原始字符串是F***T $,其中*是未知字符.
结束了我的想法.现在我必须利用全球网络并问另一个人:怎么样?
你可以说这是家庭作业,熟悉我的导师,我把我的赌注押在一个动态的编程问题上.
我正在使用以下代码,但它没有正确解密文本,我得到的是输出
加密:%öNo2F?¢SHºûÅ"?¾
明文:你好×amoriginÎl
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
// Dernier exemple CTR mode
// Clé 16 bits
byte[] keyBytes = new byte[] { (byte) 0x36, (byte) 0xf1, (byte) 0x83,
(byte) 0x57, (byte) 0xbe, (byte) 0x4d, (byte) 0xbd,
(byte) 0x77, (byte) 0xf0, (byte) 0x50, (byte) 0x51,
(byte) 0x5c, 0x73, (byte) 0xfc, (byte) 0xf9, (byte) 0xf2 };
// IV 16 bits (préfixe du cipherText)
byte[] ivBytes = new byte[] { (byte) 0x69, (byte) 0xdd, …Run Code Online (Sandbox Code Playgroud) 现在我正在创建一个将在C#.Net中执行常见任务的库.基本上我是针对C#的初学者,这样他们就可以从我的图书馆中受益并使用它来减少他们遇到的困难.我目前正在我的库中添加加密功能,并且我取得了一些成功.但我的加密标准并不是很困难和复杂.以便将来任何黑客都可以通过破解和解密重要数据(即密码等).所以请告诉我如何编写自己的复杂标准来加密密码.该库旨在免费为初学者.
谢谢
我今天正在进行加密,我的同事告诉我一个更简单/自定义的方式来做,我所做的就是列在那里,所以你能告诉我这是什么类型的加密或hashign吗?他告诉我,这是某种散列和加密的混合体.对不起愚蠢的问题,我是新来的.:)下面的方法采用一个字符串(在我的情况下密码).将其反转并生成一个字典(在下面列出添加字典项)并匹配键和值并返回加密数据.
public static string Encrypt(string source)
{
string enCrypted = "";
try
{
source = Reverse(source);
Dictionary<char, char> sourceTable = AddDictionaryItems();
char[] sourceArray = source.ToCharArray();
StringBuilder encryptedData = new StringBuilder();
foreach (char chr in sourceArray)
{
KeyValuePair<char, char> Pair;
Pair = sourceTable.First(tuple => tuple.Key == chr);
encryptedData.Append(Pair.Value);
}
enCrypted=encryptedData.ToString();
}
catch (Exception ex)
{
}
return enCrypted;
}
Run Code Online (Sandbox Code Playgroud)
下面的方法将项目添加到字典中,项目基本上是基于ascii代码.我循环遍历所有asciis然后在字典中添加相应的charachters.但真正的诀窍是在词典中添加一个项目.例如,当我在字典中添加'A'作为键时,其值将为'D'.变量"jump"指定键和值之间的差异.所以,如果我的密码是'ABC',如果我反转那个东西,它将返回'DEF'或'FED'.
public static Dictionary<char, char> AddDictionaryItems()
{
Dictionary<char, char> dc = new Dictionary<char, char>();
try
{
int initial = 33;
int jump …Run Code Online (Sandbox Code Playgroud) 我正在开发一个程序来使用AES-256和HMAC加密/解密二进制文件来检查结果.
我的代码基于Java中的AESCrypt实现,但我想修改它以允许多个线程同时完成工作.
我得到原始字节的大小并计算每个线程16字节块的数量,然后我启动线程,其中包含有关应用于读取和写入的偏移量的信息(因为加密文件有一个头,所以offset_write = offset_read + header_length).
当它完成加密时,我通过HMAC传递输出内容(没有标题)以生成校验和.
问题是某些字节在两个线程之间的字节中被破坏.
主要代码:
//..
// Initialization and creation of iv, aesKey
//..
in = new FileInputStream(fromPath);
out = new FileOutputStream(toPath);
//..
// Some code for generate the header and write it to out
//..
double totalBytes = new Long(archivo.length()).doubleValue();
int bloquesHilo = new Double(Math.ceil(totalBytes/(AESCrypt.NUM_THREADS*AESCrypt.BLOCK_SIZE))).intValue();
int offset_write = new Long((out.getChannel()).position()).intValue();
for (int i = 0; i < AESCrypt.NUM_THREADS; i++)
{
int offset = bloquesHilo*AESCrypt.BLOCK_SIZE*i;
HiloCrypt hilo = new HiloCrypt(fromPath, toPath, ivSpec, aesKey, offset, offsetInicio, …Run Code Online (Sandbox Code Playgroud) 其加密方法允许解密用数据Ñ出的中号键?
示例:共有5个人,每个人都获得一个单独的密钥.他们应该能够解密加密数据,但至少需要其中3个(任意组合)才能对其进行解密.
我一直在阅读示例代码,展示如何执行DH密钥交换.超级简单,我理解它.然而,我不知道的是p和q的适当大小应该是什么.在样本中,数字非常小.但我认为,在实践中,它们应该更大.多大了?16-22位数的素数是否足够?