Click here to Skip to main content
16,016,759 members
Home / Discussions / ASP.NET
   

ASP.NET

 
QuestionAdd control in UpdatePanel Pin
mehrdadc4824-Feb-09 20:36
mehrdadc4824-Feb-09 20:36 
AnswerRe: Add control in UpdatePanel Pin
sarang_k24-Feb-09 22:47
sarang_k24-Feb-09 22:47 
AnswerRe: Add control in UpdatePanel Pin
Mark Graham25-Feb-09 1:01
Mark Graham25-Feb-09 1:01 
Questionstring Encryption/Decryption using AES Algorithm in asp.net Pin
mani.thirumalai24-Feb-09 19:46
mani.thirumalai24-Feb-09 19:46 
AnswerRe: string Encryption/Decryption using AES Algorithm in asp.net Pin
Christian Graus24-Feb-09 20:15
protectorChristian Graus24-Feb-09 20:15 
GeneralRe: string Encryption/Decryption using AES Algorithm in asp.net Pin
mani.thirumalai24-Feb-09 20:40
mani.thirumalai24-Feb-09 20:40 
GeneralRe: string Encryption/Decryption using AES Algorithm in asp.net Pin
N a v a n e e t h24-Feb-09 21:18
N a v a n e e t h24-Feb-09 21:18 
GeneralRe: string Encryption/Decryption using AES Algorithm in asp.net Pin
mani.thirumalai24-Feb-09 22:17
mani.thirumalai24-Feb-09 22:17 
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
QuestionImport Excel Option Pin
Guvera24-Feb-09 19:34
Guvera24-Feb-09 19:34 
AnswerRe: Import Excel Option Pin
Christian Graus24-Feb-09 19:39
protectorChristian Graus24-Feb-09 19:39 
AnswerRe: Import Excel Option Pin
Jörgen Andersson24-Feb-09 20:38
professionalJörgen Andersson24-Feb-09 20:38 
AnswerRe: Import Excel Option Pin
Abhishek Sur24-Feb-09 21:22
professionalAbhishek Sur24-Feb-09 21:22 
GeneralRe: Import Excel Option Pin
Jörgen Andersson24-Feb-09 21:55
professionalJörgen Andersson24-Feb-09 21:55 
GeneralRe: Import Excel Option Pin
Greg Chelstowski24-Feb-09 22:28
Greg Chelstowski24-Feb-09 22:28 
GeneralRe: Import Excel Option Pin
Jörgen Andersson24-Feb-09 23:46
professionalJörgen Andersson24-Feb-09 23:46 
GeneralRe: Import Excel Option Pin
Greg Chelstowski25-Feb-09 1:06
Greg Chelstowski25-Feb-09 1:06 
GeneralRe: Import Excel Option Pin
Jörgen Andersson25-Feb-09 1:10
professionalJörgen Andersson25-Feb-09 1:10 
GeneralRe: Import Excel Option Pin
Abhishek Sur27-Feb-09 4:15
professionalAbhishek Sur27-Feb-09 4:15 
GeneralRe: Import Excel Option Pin
Jörgen Andersson27-Feb-09 4:19
professionalJörgen Andersson27-Feb-09 4:19 
GeneralRe: Import Excel Option Pin
Jörgen Andersson27-Feb-09 4:31
professionalJörgen Andersson27-Feb-09 4:31 
Questionplease help me Pin
sivasampathkumar24-Feb-09 19:09
sivasampathkumar24-Feb-09 19:09 
AnswerRe: please help me Pin
Christian Graus24-Feb-09 19:16
protectorChristian Graus24-Feb-09 19:16 
GeneralRe: please help me Pin
N a v a n e e t h24-Feb-09 21:20
N a v a n e e t h24-Feb-09 21:20 
QuestionImage Resize Pin
Robymon24-Feb-09 18:57
Robymon24-Feb-09 18:57 
AnswerRe: Image Resize Pin
Christian Graus24-Feb-09 19:17
protectorChristian Graus24-Feb-09 19:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.