|
There's a cryptography namespace in .NET. Your question actually has nothing to do with ASP.NET, you should nominate what language you're using and ask in that forum.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Dear Graus
Here i give the Java code. I want follow these function in asp.net.
My Java codes as follows as
import java.io.FileInputStream;
import java.io.DataInputStream;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
public class AESEncryptDecrypt {
//method to read key from the file.
private SecretKeySpec readKey() {
SecretKeySpec skeySpec=null;
try{
FileInputStream fis=new FileInputStream("D:\\keyfile.txt");
DataInputStream disFile=new DataInputStream(fis);
String key=disFile.readLine();
BASE64Decoder base64 = new BASE64Decoder();
byte[] bts=base64.decodeBuffer(key);
skeySpec = new SecretKeySpec(bts,"AES");
}catch(Exception e) {
System.out.println("error "+e);
}
return skeySpec;
}
//Method for encrypt the input value using the secret key
private String Encrypt(String msg ,SecretKeySpec skeySpec){
String hexString="";
try
{
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(msg.getBytes());
hexString=asHex(encrypted);
}catch(Exception e)
{
System.out.println("Error in Encrypt"+e);
}
return hexString;
}
//Method for decrypt the input value using the same secret key
private String Decrypt(String hexString,SecretKeySpec skeySpec)
{
String originalString = "";
try
{
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] bts = new byte[hexString.length() / 2];
for (int i = 0; i < bts.length; i++) {
bts[i] = (byte) Integer.parseInt(hexString.substring(2*i, 2*i+2), 16);
}
byte[] original = cipher.doFinal(bts);
originalString = new String(original);
}catch(Exception e)
{
System.out.println("Error in Decrypt"+e);
}
return originalString;
}
private String asHex(byte bytes[]){
StringBuffer retString = new StringBuffer();
for (int i = 0; i < bytes.length; ++i)
{
retString.append(Integer.toHexString(0x0100 + (bytes[i] & 0x00FF)).substring(1));
}
return retString.toString();
}
public static void main(String args[]){
AESEncryptDecrypt cryptoEnc = new AESEncryptDecrypt();
SecretKeySpec keySpec=cryptoEnc.readKey();
// Input For Encryption
String hexString = cryptoEnc.Encrypt("Sample Input Text",keySpec);
System.out.println("encrypted string: " + hexString);
// For Decryption
String originalString = cryptoEnc.Decrypt(hexString,keySpec);
System.out.println("Original string: " +originalString);
}
}
Reply me
Thanx
|
|
|
|
|
So, are you expecting him to convert this code to ASP.NET?
Look into the System.Security.Cryptography and work with the classes provided.
|
|
|
|
|
Dear Navaneeth
Thanx for reply.I had converted Java code to asp.net code using Java to vb.Net converter.
Here problem is SecretKeySpec,Cipher these are not supporting in .net.even if i using following classes also.
Imports System.Security.Cryptography
Imports System.Security.Cryptography.CipherMode
Imports System.Security.Cryptography.CryptoConfig
Imports System.Security.Cryptography.CryptoStream
I give the my codes as your refernce
Imports System
Imports System.Security.Cryptography
Imports System.Security.Cryptography.CipherMode
Imports System.Security.Cryptography.CryptoConfig
Imports System.Security.Cryptography.CryptoStream
Public Class JavaToAspNet
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim keySpec As SecretKeySpec = readKey()
' Input For Encryption
Dim hexString As String = Encrypt("Sample Input Text", keySpec)
Response.Write("encrypted string: " & hexString)
' For Decryption
Dim originalString As String = Decrypt(hexString, keySpec)
Response.Write("Original string: " & originalString)
End Sub
'method to read key from the file.
Private Function readKey() As SecretKeySpec
Dim skeySpec As SecretKeySpec = Nothing
Try
Dim fis As New FileInputStream("D:\keyfile.txt")
Dim disFile As New DataInputStream(fis)
Dim key As String = disFile.readLine()
Dim base64 As New BASE64Decoder
Dim bts() As SByte = base64.decodeBuffer(key)
skeySpec = New SecretKeySpec(bts, "AES")
Catch ex As Exception
Response.Write(ex.Message)
End Try
Return skeySpec
End Function
'Method for encrypt the input value using the secret key
Private Function Encrypt(ByVal msg As String, ByVal skeySpec As SecretKeySpec) As String
Dim hexString As String = ""
Try
Dim cipher As Cipher = Cipher.getInstance("AES")
cipher.init(Cipher.ENCRYPT_MODE, skeySpec)
Dim encrypted() As SByte = cipher.doFinal(msg.getBytes())
hexString = asHex(encrypted)
Catch ex As Exception
Response.Write(ex.Message)
End Try
Return hexString
End Function
'Method for decrypt the input value using the same secret key
Private Function Decrypt(ByVal hexString As String, ByVal skeySpec As SecretKeySpec) As String
Dim originalString As String = ""
Try
Dim cipher As Cipher = Cipher.getInstance("AES")
cipher.init(Cipher.DECRYPT_MODE, skeySpec)
Dim bts(hexString.Length / 2 - 1) As SByte
For i As Integer = 0 To bts.length - 1
bts(i) = CSByte(Convert.ToInt32(hexString.Substring(2 * i, 2 * i + 2), 16))
Next i
Dim original() As SByte = cipher.doFinal(bts)
originalString = New String(original)
Catch ex As Exception
Response.Write(ex.Message)
End Try
Return originalString
End Function
Private Function asHex(ByVal bytes() As SByte) As String
Dim retString As System.Text.StringBuilder = New System.Text.StringBuilder
For i As Integer = 0 To bytes.Length - 1
retString.Append(Integer.toHexString(&H100 + (bytes(i) And &HFF)).Substring(1))
Next i
Return retString.ToString()
End Function
End Class
Thanx
reply me
Regards
Mani
|
|
|
|
|
Hi friends,
We have used import excel option, in our web application. Is it necessary that MS office to be installed in the hosting server i.e where the application resides or just the dll added as reference will support to run the application.
Please guide us.
Every Successful Person Have A Painful Story
|
|
|
|
|
As far as I know, Excel needs to be installed on a machine that tries to interop with it. The dlls just provide a bridge to Excel itself.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
If you only need to access the actual data without the formatting, you can use OLEDB which is built in to dotnet.
|
|
|
|
|
some times ago,I have used to export in excel... I was just placing an html to open in excel, and it works great for me .. . If you dont want to have excel features embedded, just use that. It doesnt require Excel and easy to implement.
On the other hand, if you have Excel template and want to use that u can use Oledb. Oledb is generally better when reading from excel. It cannot create excel files. You must have a blank excel file to use OleDb.
Interop requires Excel to be installed.
Abhishek Sur
|
|
|
|
|
Abhishek Sur wrote: It cannot create excel files
That's funny, it works for me.
|
|
|
|
|
I'm sorry, how exactly do you go about creating an Excel spreadsheet WITHOUT using interop and just OleDb?
I'm not being sarcastic, it would be of great help. I just can't seem to find it anywhere... All the articles I have found so far say you need to have a spreadsheet to begin with, if you want to transfer data to and from it. (using ONLY OleDb)
var question = (_2b || !(_2b));
|
|
|
|
|
Depending on your lingual preferences
string ConnectionStr = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended properties=\"Excel 8.0;HDR=YES\"", Location);
using (OleDb.OleDbConnection Connection = new OleDb.OleDbConnection(ConnectionStr)) {
Connection.Open();
string CreateString = "CREATE TABLE...";
using (OleDb.OleDbCommand Command = new OleDb.OleDbCommand(CreateString.ToString, Connection)) {
Command.ExecuteNonQuery();
}
Connection.Close();
}
Dim ConnectionStr As String = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended properties=""Excel 8.0;HDR=YES""", Location)
Using Connection As New OleDb.OleDbConnection(ConnectionStr)
Connection.Open()
Dim CreateString as String= "CREATE TABLE..." 'Create your worksheet using normal SQL
Using Command As New OleDb.OleDbCommand(CreateString.ToString, Connection)
Command.ExecuteNonQuery()
End Using
'More code here
Connection.Close()
End Using
Location is path AND filename
Don't forget to set your permissions at the filelocation if it's a webserver.
|
|
|
|
|
Sweet!
Why did i not know about it before?
Great stuff!!
You're a star
var question = (_2b || !(_2b));
|
|
|
|
|
You're welcome.
Greg Chelstowski wrote: You're a star
|
|
|
|
|
wow... great buddy..
I never thought that it would work.. .my bad ...
Thanks really ... It will solve my all sorts of problems...
you rock
Abhishek Sur
|
|
|
|
|
|
I never thought about it before, but seeing the positive responses I get I think I'll make an article about how to make an Excelexport that doesn't need interop.
|
|
|
|
|
<big> how to put linebreak in notepad using asp.net</big>
|
|
|
|
|
It's hard when your question displays multiple levels of ignorance.
First of all, please help me is not a useful subject, although it does serve as a warning for what is within
Second, notepad cannot interact with ASP.NET. I assume you mean how to put line breaks in a text file ?
Environment.NewLine does that, although it's hard to know exactly what you're asking, and it's for sure that you're in need of reading a basic book on C# or VB.NET ( I am guessing VB ) and ASP.NET.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: It's hard when your question displays multiple levels of ignorance.
Worth for a new sig!
|
|
|
|
|
While Uploading how we can resize and convert it into .Gif format and store it into sql database. while resizing it should not go the clarity, it should get good clarity.
|
|
|
|
|
Robymon wrote: while resizing it should not go the clarity, it should get good clarity.
Well, this is a fantasy. If you resize smaller, you lose detail. If you store as gif, you lose color information, gif is only 8 bit. Within those parameters, you just create a new image, of the size you want, draw the old image into the new one, and save it as a GIF to a stream, which you can then use to get the data for your DB.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
How can i do this. can i get source code of doing this.
|
|
|
|
|
something like:
Bitmap bm = new Bitmap(newWidth, newHeight);
using (Graphics g = Graphics.FromImage(bm))
{
g.InterpolationMode = ??? // I don't recall what enum this is, or the values, set to bicubic if it's offered, or bilinear otherwise.
g.DrawImage(theOriginalImage, 0, 0, theOriginalImage.Width, theOriginalImage.Height, 0, 0, newWidth, newHeight);
}
MemoryStream s = new MemoryStream;
bm.Save(s, ImageType.Gif);
This is all from memory, it almost certainly won't compile, but it's the sort of thing you need to write. Try referring to your textbooks or google for the specifics.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thank you very much. I will try with this code.
|
|
|
|
|
Hi
How i store all Images into applcation Directroy
how i have to give the path while uploading the image
i want to store images like below Path
~\Image1.jpg
Best regrds
Rameez
|
|
|
|