我已经开发了java卡applet.it使用RSA进行加密.所以我想知道有没有办法加速java卡中的RSA加密/解密.原因是当我使用RSA 2048它需要一些额外的时间比RSA 512或1024.
谢谢SSV
我试图使用我的设备上生成的RSA密钥解密我的Android应用程序中的字符串.加密是由php服务完成的,使用我的应用程序提供的public rsa密钥.我的问题是解密,但失败了.
我正在做以下事情:
在Android上生成KeyPair(使用KeyPairGenerator.getInstance("RSA")) - >确定
两个密钥(公共和私有)在使用Base64.encode(pubKey.getEncoded())进行"base64"编码后保存到文件中,并与私钥相同. - >好的
当我调用我的webservice时,我将我的公钥(在base 64中)传递给post变量 - > OK
Web服务(php服务)使用openssl_public_encrypt函数使用公钥加密短字符串.加密的字符串将转换为base64. - >好像,函数不返回FALSE.
应用程序检索服务的结果,并对其进行解码(Base64.decode()) - > OK(我已检查,收到的字节与openssl_public_encrypt()函数生成的字节匹配)
最后一件事是解密这个字符串,我正在做以下事情: - >不行
密码密码= Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE,privateKey);
byte [] decryptedBytes = cipher.doFinal(cryptedBytes);
String decryptedString = new String(decryptedBytes);
的System.out.println(decryptedString);
解密的结果与我的原始字符串不匹配.
我错过了什么?
<?php
include("connect.php");
session_start();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Username and password sent from form in HTML
$myusername = $_POST['username'];
$mypassword = $_POST['password'];
$sql = "SELECT id FROM users WHERE username='$myusername' and password='$mypassword'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$active = $row['active'];
$count = mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if ($count == 1) {
session_register("myusername");
$_SESSION['login_user'] = $myusername;
header("location: welcome.php");
} else {
$error = "Your username or password is invalid"; …Run Code Online (Sandbox Code Playgroud) 如果我知道密钥,有人问我如何解密给定的AES 256位加密字符串.我对加密技术不太熟悉,所以我坐下来研究这个问题.
我在MSDN上找到了这个例子,并尝试修改它只做Decrypt:
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
internal class AesExample
{
public static void Main()
{
var encryptedString = "U2FsdGVkX1/cHT8XuHCfpw0AV4jpaO8JfLqUeCRJqjY=";
var secret = "SPARKY";
// I know this is not the correct way to get my input byte arrays...
// Just illustrating that I DO need byte arrays.
var encryptedBytes = Encoding.UTF8.GetBytes(encryptedString);
var secretBytes = Encoding.UTF8.GetBytes(secret);
try
{
using (var aes = new AesManaged())
{
aes.Key = secretBytes;
// Decrypt the bytes …Run Code Online (Sandbox Code Playgroud) 我想使用其ASCII值将字符加密(RSA)为整数.例如.'a'加密为48.
对于加密:c=pow(m,e)%n其中c是密文,m是纯文本,(e,n)是公钥.
如果pow(m,e)很大,比如67 ^ 7,它将不适合int或long.但是,如果我使用double,我不能将它与模数%运算符一起使用.所以我使用for循环编写了这个加密函数:
int encrypt(int m, int e, int n)
{
int res=m, i;
for(i=0; i<e-1;i++)
res=(res*res)%n;
return res;
}
Run Code Online (Sandbox Code Playgroud)
它适用于67 ^ 7mod11,这是67但后来我才知道它实际上并不正确.我哪里出错了?
我有一个用Python加密SHA-1的功能hashlib.我拿一个文件并用这个哈希加密内容.
如果我为加密文本文件设置了密码,我可以使用此密码解密并使用原始文本还原文件吗?
所以我知道MD5在技术上是新应用程序中的禁忌,但我随机想到了这个:
以来
md5($password);
Run Code Online (Sandbox Code Playgroud)
不安全,不会
md5(md5($password))
Run Code Online (Sandbox Code Playgroud)
是一个更好的选择?我使用的越多,它会越来越安全吗?假如我做了这样的功能
Run Code Online (Sandbox Code Playgroud)function ExtremeEncrypt($password) { $encryptedpass = md5(sha1(md5(md5($pass)))); return $encryptedpass; }
如果像vbulletin那样为每个帐户使用随机盐,这个函数是否会是一个很好的选择.
我读了一些关于将密钥从PEM转换为DER的已知问题,以便Java可以读取它们,我跑了这篇文章.当跟进时,这工作正常 - 生成的RSA密钥对openssl,密钥加载正常,用公钥加密的内容用私钥成功解码.
现在,这是不清楚的部分.
不久前,我使用Easy-RSA实用程序生成PKI,同时设置OpenVPN服务器.在这里,创建了一个自签名证书.输出文件包括:
server.csr ------ //证书请求
server.key ------ //私钥
server.crt ------- //自签名证书/公钥/无论这是什么..?
Just for the reference, easy-RSA is documented (on the bottom of the page are the scripts explained, and we can see openssl commands actually used in the process).
So, I tried the above logic on these files, using server.key as my private key file, and server.crt as my public key file, both previously transformed to Java-readable DER format:
openssl pkcs8 -topk8 -inform …
我回过头来看一些代码[包含在这篇文章的底部],我之前写过一些加密,我遇到了一个我无法找到解决方法的错误.每当我尝试解密我的数据时,我都会从OpenSSL中收到以下错误:
error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
Run Code Online (Sandbox Code Playgroud)
我的加密功能的输出是:
$AES-256-CBC$SHA256$kJ+DIShnFOs0cGsDiVnXXMdBj1GoLYywrhz+lv3W/dk=
Run Code Online (Sandbox Code Playgroud)
原始的加密数据是:
00000000 90 9f 83 21 28 67 14 eb 34 70 6b 03 89 59 d7 5c |...!(g..4pk..Y.\|
00000010 c7 41 8f 51 a8 2d 8c b0 ae 1c fe 96 fd d6 fd d9 |.A.Q.-..........|
Run Code Online (Sandbox Code Playgroud)
我的IV是:
00000000 d7 4f f0 ee 8d a3 b9 80 6b 18 c8 77 db f2 9b bd |.O......k..w....|
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚这里出了什么问题.我可以谷歌的大多数归结为"你没有从数据的开头删除IV",但它从来没有在第一位.
码:
Class MyEncrypt {
private $method, $iv_size, $hashfunc;
public function __construct($method='AES-256-CBC', $hashfunc='SHA512') {
if( …Run Code Online (Sandbox Code Playgroud) 我有两张AES加密票(见下文)和它的明文.我可以从这些信息中找到AES密钥吗?
加密类型:使用PKCS#5填充的AES CBC加密
两张加密票:CD46F0E2B829FBF75CA5A93D35CAF5FB3FFB997D7ADB606CD7F82DAE0D79859B84EA91D7D6A7F6FAF45C59DF370F1E31BEEF0000BEEF0000BEEF0000BEEF0000明文值:20101010
6B4CF1C63C819AA79437BEBF2189F672A40CB30AF1E8B2C7857A2C458DF8DFD286E898D4D6A7F6FAF66B67DD350D1C33BEEF0000BEEF0000BEEF0000BEEF0000明文值:20101209