我一直在为RSA算法编写代码.它运作良好,但不幸的是它显示了小'w','z','x','y'的错误答案.
我的加密算法很简单.使用两个不同的素数和'e'我生成公钥,然后通过生成'd'我创建了私钥.然后使用BIGMOD(快速取幂)算法,我只计算模数部分进行加密和解密.这是我的代码:
#include<stdio.h>
#include<string.h>
long long int square(long long int a);
long long int BigMod(int M,int E,int N);
void encrypt(int l,int E,int N);
void decrypt(int E,int N );
int main()
{
main_RSA();
return 0;
}
void main_RSA()
{
int p,q;
printf("Write two distinct Prime number separated by space:");
scanf("%d %d",&p,&q);
int n=p*q;
int phi=(p-1)*(q-1);
int e;
printf("Enter a prime number 'e' as GCD(e,(P-1)*(Q-1)) : ");
scanf("%d",&e);
printf("public key( e , n ) : ( %d %d )\n",e,n);
int d,RES=-1;
for(d=1;;d++){ …Run Code Online (Sandbox Code Playgroud) 嗨,我是Android和图像加密的新手.我的情况是这样的,
(请参阅我已经使用的所有需要方法的底部..)
但是我得到了javax.crypto.BadPaddingException:解密时pad块被破坏了.我读了一些关于这个例外的文章,但都是关于文本加密的.你能帮我避免这个吗?先感谢您
Image Encrption使用...
private byte[] encrypt(byte[] raw, byte[] clear) throws Exception
{
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
}
Run Code Online (Sandbox Code Playgroud)
在这里我也保存了其他几张图片,所有图像都成功保存在SD卡中...
for (int i = 0; i < imageUrls.size(); i++)
{
File file = new File(imageUrls.get(i));
String metapath = CommonUtils.getDataFromPreferences("metaPath", "");
Log.d("metapath", metapath);
String extStorageDirectory = metapath + file.getName();
File wallpaperDirectory = new File(extStorageDirectory);
if (!wallpaperDirectory.exists() || wallpaperDirectory.length() == 0)
{
new DownloadImagesTask() …Run Code Online (Sandbox Code Playgroud) 我的网站上有以下代码.它将URL查询作为名为commandencrypted的字符串.我有一个try/catch/finally块,将加密的命令复制到一个MemoryStream,然后解密回一个字符串.如果发生在try块中的任何错误,他们在catch块处理.不过,我要确保所使用的任何资源finally块中被关闭.当提供无效的URL查询命令,我收到一个异常,而试图关闭csencryptedcommand CryptoStream的.例外细节遵循代码.
// Resources used for storing and decrypting the encrypted client command
MemoryStream msencryptedcommand = null;
RijndaelManaged rmencryptedcommand = null;
CryptoStream csencryptedcommand = null;
StreamReader srdecryptedcommand = null;
MemoryStream msdecryptedcommand = null;
try
{
// Copy the encrypted client command (where two characters represent a byte) to a memorystream
msencryptedcommand = new MemoryStream();
for (int i = 0; i < encryptedcommand.Length; )
{
msencryptedcommand.WriteByte(Byte.Parse(encryptedcommand.Substring(i, 2), NumberStyles.HexNumber));
i = i + 2;
}
msencryptedcommand.Flush();
msencryptedcommand.Position = 0;
// Define parameters …Run Code Online (Sandbox Code Playgroud) 如何从此方法中反转此输出?(这样我就可以看到明文了)我没有看到任何键被使用.
public String encrypt(String plaintext) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA");
} catch (NoSuchAlgorithmException e) {
}
try {
md.update(plaintext.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
}
byte raw[] = md.digest();
String hash = (new BASE64Encoder()).encode(raw);
return hash;
}
Run Code Online (Sandbox Code Playgroud) 我想写一个AES加密方法,它应该等同于mysql aes_encrypt.
我尝试写但是它不正确,因为mysql也没有给出正确的数据.
我该怎么做才能使它正确?
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, keySpec);
byte[] encryptedTextBytes = cipher.doFinal(message .getBytes("UTF-8"));
String k = new String(encryptedTextBytes);
System.out.println("KKKKK"+k);
Run Code Online (Sandbox Code Playgroud) 基于此页面,我做了以下内容:
我猜我在尝试通过我的C:目录调用Web.config文件时做错了什么?
然后我阅读了步骤3.4的部分,并通过使用aspnet_regiis -pef"connectionStrings"C:FirstName-Projects/ProjName-TEST prov"DataProtectionConfigurationProvider"尝试了-pef,这导致我可以提供的所有注册选项的完整列表.
任何人都可以根据C:/FirstName-Projects/ProjName-TEST/SolutionName/Web.config中的Web.config文件向我提供一些使用内容的输入吗?
假设我想将"password-derived-bytes"作为AES密钥.例如,我有一个密码"topsecret",我确实为它计算了SHA-1哈希值(160位),我想将这些字节作为AES-128的密钥.
我应该在128位之后截断还是做某种折叠?AES-256怎么样?我应该重复字节,填0或做一些"展开"操作?
我知道在后一种情况下,安全性保持在160位,因为256位密码池减少到2 ^ 160种可能的组合,但我只是想克服技术限制(没有AES-160).
什么理论说?(不,使用MD5进行128位,使用SHA-256进行256位长哈希不是一种选择)
我试图使用"表单集成"方法将SagePay支付网关集成到网站中.
基本上,表单集成方法的工作原理是,只要选择了FORM的Submit按钮,就可以在网页中插入FORM并将信息发布到SagePay的服务器.在将信息发送到SagePay的服务器之前,必须使用AES/CBC/PKCS#5算法对其进行加密,然后再进行Base 64编码.
我有加密的基本知识,但我没有在PHP中使用它的经验.有谁能帮我用PHP制定AES/CBC/PKCS#5算法?
到目前为止,这是我的努力:
$CRYPT = "Text Goes Here";
$blocksize = 16;//Does 16 Refer To 16 Bytes Or 16 Bits? 16 Bytes = 128 Bits.
$cryptLength = strlen($CRYPT);
$cryptLengthModuloBlocksize = $cryptLength % $blocksize;
$pad = $blocksize - $cryptLengthModuloBlocksize;
$padString = str_repeat(chr($pad), $pad);
$CRYPT = $CRYPT . $padString;
$encryptionPassword = 'password';
$Encrypted_CRYPT = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $encryptionPassword, $CRYPT, MCRYPT_MODE_CBC);
$Base64_Encrypted_CRYPT = base64_encode($Encrypted_CRYPT);
echo "<form action = 'https://test.sagepay.com/gateway/service/vspform-register.vsp' method = 'POST'>
<input type = 'hidden' name = 'VPSProtocol' value = '3.00' />//
<input …Run Code Online (Sandbox Code Playgroud) 我正在尝试生成像我的应用程序中使用的youtube视频ID的短字符串哈希,但我无法弄清楚什么是最快和最简单的方法,同时使用数组或基于json的字符串提供最短的哈希.
我读了Kevin van Zonneveld 关于这个主题的优秀文章,他根据整数生成alphaID,它有两种方式.还有很好的答案,但我的情况有点不同:
对于数据库中的每个唯一记录,有很多(超过100K)但很小的数据集(数组):
$id = 1;
$set[$id] = array(533 => array('a' => 78), 460 => array('a' => 89));
$set[$id] = array(534 => array('b' => 79), 620 => array('a' => 908));
$set[$id] = array(535 => array('a' => 80), 782 => array('c' => 901));
$id = 2;
$set[$id] = array(672 => array('a' => 12), 852 => array('a' => 122));
$set[$id] = array(542 => array('a' => 67), 372 => array('a' => 831));
$set[$id] = array(573 => array('a' => …Run Code Online (Sandbox Code Playgroud)我已经读到了现在在CQ5.5 +中的Adobe CryptoSupport,它旨在提供一个加密和解密数据的实用程序,例如,更安全地在JCR中存储API密钥.
该JavaDoc中或一般的Adobe文档提供有关其执行任何细节,只是指出:
请注意,此方法和
decrypt(byte[])方法提供完整的往返支持:Run Code Online (Sandbox Code Playgroud)decrypt(encrypt(plainText)).equals(plainText) == true请注意,在同一方法上调用此方法两次
plainText不会返回相同的密文:Run Code Online (Sandbox Code Playgroud)encrypt(plainText).equals(encrypt(plainText)) == false
这是非常有用的,但它没有告诉我这些密码是如何开始加密的.我尝试在一个CQ实例上加密并在另一个CQ实例上解密,但这似乎不起作用.
为了充满信心地使用这个功能,我想知道CQ加密的基础.我有两个主要问题: