2022年3月4日 星期五

[VB.NET] 簡易加密解密工具

 





Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

    End Sub

    Private Sub btnEnter_Click(sender As Object, e As EventArgs) Handles btnEnEnter.Click
        If txtKey.Text.Trim.Length <> 8 Then
            MsgBox("Key請設定為8位數!")
            Exit Sub
        End If
        txtPassword.BackColor = Color.LightGreen
        txtENPassword.BackColor = Color.White
        txtPassword.Text = Decrypt(txtENPassword.Text.Trim, txtKey.Text.Trim)
    End Sub
    Private Sub btnDeEnter_Click(sender As Object, e As EventArgs) Handles btnDeEnter.Click
        If txtKey.Text.Trim.Length <> 8 Then
            MsgBox("Key請設定為8位數!")
            Exit Sub
        End If
        txtENPassword.BackColor = Color.LightGreen
        txtPassword.BackColor = Color.White
        txtENPassword.Text = Encrypt(txtPassword.Text.Trim, txtKey.Text.Trim)
    End Sub

    Private Sub btnClean_Click(sender As Object, e As EventArgs) Handles btnClean.Click
        txtENPassword.Text = ""
        txtPassword.Text = ""
        txtPassword.BackColor = Color.White
        txtENPassword.BackColor = Color.White
    End Sub


#Region "字串解密"
    Public Function Decrypt(ByVal vsToDecrypt As String, ByVal vsKey As String) As String
        Try
            Dim des As New System.Security.Cryptography.DESCryptoServiceProvider()
            ''把字符串放入byte數組
            Dim len As Integer
            len = vsToDecrypt.Length / 2 - 1
            Dim inputByteArray(len) As Byte
            Dim x, i As Integer
            For x = 0 To len
                i = Convert.ToInt32(vsToDecrypt.Substring(x * 2, 2), 16)
                inputByteArray(x) = CType(i, Byte)
            Next

            ''建立加密對象的密鑰和偏移量,此值重要,不能修改
            des.Key = System.Text.ASCIIEncoding.ASCII.GetBytes(vsKey)
            des.IV = System.Text.ASCIIEncoding.ASCII.GetBytes(vsKey)

            Dim ms As New System.IO.MemoryStream()
            Dim cs As New System.Security.Cryptography.CryptoStream(ms, des.CreateDecryptor, System.Security.Cryptography.CryptoStreamMode.Write)

            cs.Write(inputByteArray, 0, inputByteArray.Length)
            cs.FlushFinalBlock()

            Return System.Text.Encoding.Default.GetString(ms.ToArray)
        Catch ex As Exception
            Return ""
        End Try
    End Function
#End Region


#Region "字串加密"
    Public Function Encrypt(ByVal vsToEncrypt As String, ByVal vsKey As String) As String
        Dim des As New System.Security.Cryptography.DESCryptoServiceProvider()
        Dim inputByteArray() As Byte
        inputByteArray = System.Text.Encoding.Default.GetBytes(vsToEncrypt)
        ''建立加密對象的密鑰和偏移量
        ''原文使用ASCIIEncoding.ASCII方法的GetBytes方法
        ''使得輸入密碼必須輸入英文文本
        des.Key = System.Text.ASCIIEncoding.ASCII.GetBytes(vsKey)
        des.IV = System.Text.ASCIIEncoding.ASCII.GetBytes(vsKey)
        ''寫二進制數組到加密流
        ''(把內存流中的內容全部寫入)
        Dim ms As New System.IO.MemoryStream()
        Dim cs As New System.Security.Cryptography.CryptoStream(ms, des.CreateEncryptor, System.Security.Cryptography.CryptoStreamMode.Write)
        ''寫二進制數組到加密流
        ''(把內存流中的內容全部寫入)
        cs.Write(inputByteArray, 0, inputByteArray.Length)
        cs.FlushFinalBlock()
        ''建立輸出字符串
        Dim ret As New System.Text.StringBuilder()
        Dim b As Byte
        For Each b In ms.ToArray()
            ret.AppendFormat("{0:X2}", b)
        Next
        Return ret.ToString()
    End Function
#End Region
End Class


2022年2月17日 星期四

[Teams練功房]視訊會議背景設定 文字翻轉

使用Teams 視訊會議可以更換自己的背景特效

但是當選擇有文字的時候,我們可以注意到背景是靜像的,也就是文字是相反的

起初還以為是Teams的Bug,畢竟使用過Zoom的都知道有靜像這個選項可以自由決定

反之目前我使用的是企業版的Teams是沒有這個選項的,我的版本是1.5.00.2164(64位元) 給你參考


但經過實測,雖然自己是反向的,但其他參加會議的人員看到的方向是正確的,
所以當設計背景的人建議還是別加上文字啊😅😅
不然真的是讓IT頭很暈,需要一直要解釋








2022年2月8日 星期二

[Skype for Business] Exchange needs your credentials. Until then you might see outdated info in Skype for Business

 Skype for Business 偶而會在訊息欄處跳出訊息,上面顯示【Exchange needs your credentials. Until then you might see outdated info in Skype for Business】


少了這個與AD的認證會影響到行事曆的提醒


目前測試可以直接成功的解法,在檔案總管中直接開啟下面路徑

%UserProfile%\AppData\Local\Microsoft\Office\16.0\Lync


操作步驟

1.先結束Skype for Business

2.找到路徑【%UserProfile%\AppData\Local\Microsoft\Office\16.0\Lync】底下的資料夾可以找到sip_user@domain.com資料夾,可直接刪除

3.重新啟動Skype for Business即可





2022年2月7日 星期一

[VB.NET]判斷月份天數

因應2月份不固定最後一天的天數,如果單純寫成30或31天都會造成程式上的錯誤,所以還是直接使用判斷來指定天數會比較妥當。

 OrderYear =2022

OrderMonth =2


            Dim DatestringStart As String = OrderYear & "/" & OrderMonth & "/01"

            Dim Days As Integer = System.DateTime.DaysInMonth(OrderYear, OrderMonth)

            Dim DatestringEnd As String = OrderYear & "/" & OrderMonth & "/" & Days


參考資料

DateTime.DaysInMonth(Int32, Int32) 方法

2022年1月11日 星期二

[Vb.NET] 搜尋指定文字資料夾 & 尋找資料夾中的副檔名 或 特定文字

         Dim sSourcePath As String = txtDirection.Text.Trim

        Dim sDestPath As String = ""

        Dim sTextToFind As String = "搜尋指定文字資料夾"

        Dim FolderName As String = ""

        Dim PrinterFolderPath As String = sSourcePath


        For Each sDir In Directory.GetDirectories(sSourcePath, "*" & sTextToFind & "*")

            FolderName = Path.GetFileName(sDir)

            PrinterFolderPath = sSourcePath & "\" & FolderName

            Dim di As New DirectoryInfo(PrinterFolderPath)



            '抓取資料夾中檔名,並只取PDF

            For Each fi As FileInfo In di.GetFiles()

                If fi.Extension.ToLower = ".pdf" Then

                   '資料夾中檔案副檔名是PDF的

                End If

           

                If fi.Name.ToLower.Contains("TEST") Then

                   '找出資料夾中的檔案名稱有包含TEST的

                End If


            Next

        Next