- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章VBS 加解密 For CAPICOM由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
复制代码 代码如下
'****************************************************************************** ' ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, ' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED ' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. ' ' Copyright (C) 1999- 2002. Microsoft Corporation. All rights reserved. ' '****************************************************************************** ' ' CEncrypt.vbs ' ' This is a sample script to illustrate how to use the CAPICOM's EncryptedData ' to encrypt/decrypt text file. ' ' Note: For simplicity, this script does not handle exception. ' '****************************************************************************** Option Explicit Const ForReading = 1, ForWriting = 2 ' Command. Const Unknown = 0 Const Encrypt = 1 Const Decrypt = 2 ' CAPICOM's constants. Const CAPICOM_ENCRYPTION_ALGORITHM_RC2 = 0 Const CAPICOM_ENCRYPTION_ALGORITHM_RC4 = 1 Const CAPICOM_ENCRYPTION_ALGORITHM_DES = 2 Const CAPICOM_ENCRYPTION_ALGORITHM_3DES = 3 Const CAPICOM_ENCRYPTION_ALGORITHM_AES = 4 Const CAPICOM_ENCRYPTION_KEY_LENGTH_MAXIMUM = 0 Const CAPICOM_ENCRYPTION_KEY_LENGTH_40_BITS = 1 Const CAPICOM_ENCRYPTION_KEY_LENGTH_56_BITS = 2 Const CAPICOM_ENCRYPTION_KEY_LENGTH_128_BITS = 3 Const CAPICOM_ENCRYPTION_KEY_LENGTH_192_BITS = 4 Const CAPICOM_ENCRYPTION_KEY_LENGTH_256_BITS = 5 ' Command line arguments. Dim Command : Command = Unknown Dim Password : Password = Null Dim Algorithm : Algorithm = CAPICOM_ENCRYPTION_ALGORITHM_RC2 Dim KeyLength : KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_MAXIMUM Dim Verbose : Verbose = False Dim FileNames() ' First make sure the script is executed by CScript.exe. If InStr(1, UCase(Wscript.FullName), "CSCRIPT.EXE", vbTextCompare) = 0 Then Wscript.Echo "This script can only be executed by CScript.exe." & vbCRLF & vbCRLF &_ "You can either:" & vbCRLF & vbCRLF & _ "1. Set CScript.exe as the default (Run CScript //h:cscript), or" & vbCRLF & _ "2. Run CScript.exe directly as in, CScript " & Wscript.ScriptName & "." Wscript.Quit(-1) End If ' Parse the command line. ParseCommandLine ' Now process the command. Select Case Command Case Encrypt DoEncryptCommand FileNames, Algorithm, KeyLength, Password Case Decrypt DoDecryptCommand FileNames, Password End Select Wscript.Quit(0) ' End Main '****************************************************************************** ' ' Subroutine: DoEncryptCommand ' ' Synopsis : Encrypt content of text file FileNames(0). ' ' Parameter : FileNames - Array of filenames. ' ' Algorithm - Encryption algorithm ' ' KeyLength - Key size. ' ' Password - Secret password. ' '****************************************************************************** Sub DoEncryptCommand (FileNames, Algorithm, KeyLength, Password) Dim Content Dim Message Dim EncryptedData ' Create the EncryptedData object. Set EncryptedData = CreateObject("CAPICOM.EncryptedData") ' Set algorithm, key size, and encryption password. EncryptedData.Algorithm.Name = Algorithm EncryptedData.Algorithm.KeyLength = KeyLength EncryptedData.SetSecret Password ' Display main title. Wscript.Stdout.Writeline "Encrypting text file " & FileNames(0) & "." Wscript.Stdout.Writeline ' Display more detail for verbose operation. If Verbose Then DisplayDetail EncryptedData End If ' Load content of text file to be encrypted. LoadFile FileNames(0), Content ' Now encrypt it. EncryptedData.Content = Content Message = EncryptedData.Encrypt ' Finally, save encrypted message to FileNames(1). SaveFile FileNames(1), Message Wscript.Stdout.Writeline "Successful - Encrypted message saved to " & FileNames(1) & "." ' Free resources. Set EncryptedData = Nothing End Sub ' End DoEncryptCommand '****************************************************************************** ' ' Subroutine: DoDecryptCommand ' ' Synopsis : Decrypt an encrypted file. ' ' Parameter : FileNames - Array of filenames. ' ' Password - Secret password. ' '****************************************************************************** Sub DoDecryptCommand (FileNames, Password) Dim Message Dim EncryptedData ' Create the EncryptedData object. Set EncryptedData = CreateObject("CAPICOM.EncryptedData") ' Set decryption password. EncryptedData.SetSecret Password ' Display main title. Wscript.Stdout.Writeline "Decrypting encrypted text file " & FileNames(0) & "." Wscript.Stdout.Writeline ' Load the encrypted message. LoadFile FileNames(0), Message ' Now decrypt it. EncryptedData.Decrypt(Message) ' Display more detail for verbose operation. If Verbose Then DisplayDetail EncryptedData End If ' Finally, save decrypted content to FileNames(1). SaveFile FileNames(1), EncryptedData.Content Wscript.Stdout.Writeline "Successful - Decrypted content saved to " & FileNames(1) & "." ' Free resources. Set EncryptedData = Nothing End Sub ' End DoDecryptCommand '****************************************************************************** ' ' Subroutine: LoadFile ' ' Synopsis : Read content of a text file. ' ' Parameter : FileName - Input text filename. ' ' Buffer - String buffer to receive the text file content. ' '****************************************************************************** Sub LoadFile (FileName, Buffer) Dim fso Set fso = CreateObject("Scripting.FileSystemObject") If Not fso.FileExists(FileName) Then Wscript.Stdout.Writeline "Error: File " & FileName & " not found." Wscript.Quit(-5) End If Dim ts Set ts = fso.OpenTextFile(FileName, ForReading) Buffer = ts.ReadAll End Sub ' End LoadFile '****************************************************************************** ' ' Subroutine: SaveFile ' ' Synopsis : Save string to file. ' ' Parameter : FileName - Output filename. ' ' Buffer - String buffer to be saved. ' '****************************************************************************** Sub SaveFile (FileName, Buffer) Dim fso Set fso = CreateObject("Scripting.FileSystemObject") Dim ts Set ts = fso.OpenTextFile(FileName, ForWriting, True) ts.Write Buffer End Sub ' End SaveFile '****************************************************************************** ' ' Subroutine: DisplayDetail ' ' Synopsis : Display detail information. ' ' Parameter : EncryptedData - EncryptedData object. ' '****************************************************************************** Sub DisplayDetail (EncryptedData) Dim AlgoNames(4) AlgoNames(0) = "RC2" AlgoNames(1) = "RC4" AlgoNames(2) = "DES" AlgoNames(3) = "3DES" AlgoNames(4) = "AES" Wscript.Stdout.Writeline "Algorithm : " & AlgoNames(EncryptedData.Algorithm.Name) Wscript.Stdout.Write "Key length: " Select Case EncryptedData.Algorithm.KeyLength Case CAPICOM_ENCRYPTION_KEY_LENGTH_40_BITS Wscript.Stdout.Writeline "40 bits" Case CAPICOM_ENCRYPTION_KEY_LENGTH_56_BITS Wscript.Stdout.Writeline "56 bits" Case CAPICOM_ENCRYPTION_KEY_LENGTH_128_BITS Wscript.Stdout.Writeline "128 bits" Case CAPICOM_ENCRYPTION_KEY_LENGTH_192_BITS Wscript.Stdout.Writeline "192 bits" Case CAPICOM_ENCRYPTION_KEY_LENGTH_256_BITS Wscript.Stdout.Writeline "256 bits" Case Else Wscript.Stdout.Writeline "Maximum" End Select Wscript.Stdout.Writeline End Sub ' End DisplayDetail '****************************************************************************** ' ' Subroutine: ParseCommandLine ' ' Synopsis : Parse the command line, and set the options accordingly. ' ' Parameter : None ' '****************************************************************************** Sub ParseCommandLine ' Constants for command line parsing states. Const ARG_STATE_COMMAND = 0 Const ARG_STATE_OPTIONS = 1 Const ARG_STATE_ALGORITHM = 2 Const ARG_STATE_LENGTH = 3 Const ARG_STATE_FILENAME = 4 Const ARG_STATE_PASSWORD = 5 Const ARG_STATE_END = 6 ' Parse command line. Dim Arg Dim ArgState : ArgState = ARG_STATE_COMMAND For Each Arg In Wscript.Arguments Select Case ArgState Case ARG_STATE_COMMAND Select Case UCase(Arg) Case "ENCRYPT" Command = Encrypt Case "DECRYPT" Command = Decrypt Case Else DisplayUsage End Select ArgState = ARG_STATE_OPTIONS Case ARG_STATE_OPTIONS Select Case UCase(Arg) Case "-ALG", "/ALG" ArgState = ARG_STATE_ALGORITHM Case "-LENGTH", "/LENGTH" ArgState = ARG_STATE_LENGTH Case "-V", "/V" Verbose = True Case "-?", "/?" DisplayUsage Case Else If Left(Arg, 1) = "-" OR Left(Arg, 1) = "/" Then DisplayUsage Else ReDim FileNames(0) FileNames(0) = Arg End If ArgState = ARG_STATE_FILENAME End Select Case ARG_STATE_ALGORITHM If Left(Arg, 1) = "-" OR Left(Arg, 1) = "/" Then DisplayUsage Else Select Case UCase(Arg) Case "RC2" Algorithm = CAPICOM_ENCRYPTION_ALGORITHM_RC2 Case "RC4" Algorithm = CAPICOM_ENCRYPTION_ALGORITHM_RC4 Case "DES" Algorithm = CAPICOM_ENCRYPTION_ALGORITHM_DES Case "3DES" Algorithm = CAPICOM_ENCRYPTION_ALGORITHM_3DES Case "AES" Algorithm = CAPICOM_ENCRYPTION_ALGORITHM_AES Case Else DisplayUsage End Select End If ArgState = ARG_STATE_OPTIONS Case ARG_STATE_LENGTH If Left(Arg, 1) = "-" OR Left(Arg, 1) = "/" Then DisplayUsage Else Select Case UCase(Arg) Case "40" KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_40_BITS Case "56" KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_56_BITS Case "128" KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_128_BITS Case "192" KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_192_BITS Case "256" KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_256_BITS Case "MAX" KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_MAXIMUM Case Else DisplayUsage End Select End If ArgState = ARG_STATE_OPTIONS Case ARG_STATE_FILENAME If Left(Arg, 1) = "-" OR Left(Arg, 1) = "/" Then DisplayUsage Else ReDim Preserve FileNames(UBound(FileNames) + 1) FileNames(UBound(FileNames)) = Arg End If ArgState = ARG_STATE_PASSWORD Case ARG_STATE_PASSWORD If Left(Arg, 1) = "-" OR Left(Arg, 1) = "/" Then DisplayUsage Else Password = Arg End If ArgState = ARG_STATE_END Case Else Wscript.Stdout.Writeline "Internal script error: Unknown argument state (" & CStr(ArgState) & ") encountered." Wscript.Quit(-3) End Select Next ' Make sure we are in good state. If ArgState <> ARG_STATE_END Then DisplayUsage End If End Sub ' ParseCommandLine '****************************************************************************** ' ' Subroutine: DisplayUsage ' ' Synopsis : Display the usage screen, and then exit with a negative error ' code. ' ' Parameter : None. ' '****************************************************************************** Sub DisplayUsage Select Case Command Case Unknown Wscript.Stdout.Writeline "Usage: CEncrypt Command [Options] InFile OutFile Password" Wscript.Stdout.Writeline Wscript.Stdout.Writeline "Command:" Wscript.Stdout.Writeline Wscript.Stdout.Writeline " Encrypt -- Encrypt a text file" Wscript.Stdout.Writeline " Decrypt -- Decrypt an encrypted text file" Wscript.Stdout.Writeline Wscript.Stdout.Writeline "For help on a specific command, enter ""CEncrypt Command -?""" Case Encrypt Wscript.Stdout.Writeline "Usage: CEncrypt Encrypt [Options] ContentFile EncryptedFile Password" Wscript.Stdout.Writeline Wscript.Stdout.Writeline "The Encrypt command is used to encrypt a text file based on a secret password." Wscript.Stdout.Writeline "Encrypting protects the data from being read by others except those who know" Wscript.Stdout.Writeline "the secret password." Wscript.Stdout.Writeline Wscript.Stdout.Writeline "Options:" Wscript.Stdout.Writeline Wscript.Stdout.Writeline " -alg <algorithm> -- RC2, RC4, DES, 3DES, or AES (default to RC2)" Wscript.Stdout.Writeline " -length <key length> -- 40, 56, 128, 192, 256, or MAX (default to MAX," Wscript.Stdout.Writeline " and ignored for DES or 3DES)" Wscript.Stdout.Writeline " -v -- Verbose operation" Wscript.Stdout.Writeline " -? -- This help screen" Wscript.Stdout.Writeline Wscript.Stdout.Writeline " ContentFile -- Text file to be encrypted" Wscript.Stdout.Writeline Wscript.Stdout.Writeline " EncryptedFile -- Encrypted text file" Wscript.Stdout.Writeline Wscript.Stdout.Writeline "Note: All non-fatal invalid options for this specific command will be ignored." Wscript.Stdout.Writeline Case Decrypt Wscript.Stdout.Writeline "Usage: CEncrypt Decrypt [Options] EncryptedFile ContentFile Password" Wscript.Stdout.Writeline Wscript.Stdout.Writeline "The Decrypt command is used to decrypt an encrypted text file." Wscript.Stdout.Writeline Wscript.Stdout.Writeline "Options:" Wscript.Stdout.Writeline Wscript.Stdout.Writeline " -v -- Verbose operation" Wscript.Stdout.Writeline " -? -- This help screen" Wscript.Stdout.Writeline Wscript.Stdout.Writeline " EncryptedFile -- Encrypted text file" Wscript.Stdout.Writeline Wscript.Stdout.Writeline " ContentFile -- Decrypted text file" Wscript.Stdout.Writeline Wscript.Stdout.Writeline "Note: All non-fatal invalid options for this specific command will be ignored." Wscript.Stdout.Writeline Case Else Wscript.Stdout.Writeline "Internal script error: Unknown help state (Command = " & CStr(Command) & ")." Wscript.Quit(-2) End Select Wscript.Quit(-1) End Sub ' End DisplayUsage 。
最后此篇关于VBS 加解密 For CAPICOM的文章就讲到这里了,如果你想了解更多关于VBS 加解密 For CAPICOM的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我有一个 C# 应用程序调用 Java 网络服务来验证用户密码。我想让 C# 应用程序加密密码,然后让 Java Web 服务解密密码。我已经完成了 Java 端的代码(解密代码),但我无法找出 C#
我正在使用以下代码在使用 openssl 的 Windows 中使用 C 加密和解密二进制数据。如您所见,在这两个函数中,我都知道纯文本的大小。有什么方法可以在不知道纯文本大小的情况下解密消息? #i
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我有一个非常恼人的问题,Java中使用RSA算法对字符串进行不可靠的加密和解密。它似乎只能在大约 35% 的时间内工作,而且我不明白为什么它有时能工作,有时却不能。这是我写的一些测试代码,试图验证加密
我已经设法编写了用于文件加密/解密的函数。但它非常慢,尤其是随着文件大小的增加。例如几MB长的音频/视频文件 我几乎浏览了所有帖子来改进它,并尝试更改算法。如果有任何更改可以帮助我提高性能,请帮助我。
我正在尝试让我的转置密码发挥作用。 每当我将加密方法得到的密文输入解密方法时,我应该得到原始的明文......但事实并非如此...... 我做错了什么? 感谢您的帮助! public String E
我正在使用密码来加密和解密消息: public String encrypt(String string) throws InvalidKeyException, IllegalBlockSizeEx
我有一个在 MySQL 中存储数据的 spring-mvc 堆栈。其中一些数据需要保护,所以我想我应该加密它。由于我以后可能需要使用这些数据(信用卡、SSN 等),所以我需要对其进行解密。我认为这排除
作为一名SEOER,都想了解百度算法,通过算法原理来找到捷径的优化方案,那么今天我把研究多年的百度算法原理解密给大家,可能不是最好的,但是我可以给大家保证,这些都是非常实际的。希望给SEOER带来一
我试图找到一种技术来加密和解密程序中的文件,而无需将密码硬编码到程序中,也无需向用户询问密码。 如果我也可以从我正在编写的另一个程序中解密文件,那就太好了。 到目前为止,我还没有多少运气找到一种看起来
有没有一种方法可以使用作为字符串参数传递给程序的私钥而不是使用存储在机器上的证书来解密 PowerShell 中的 RSA?欢迎任何帮助,我的代码如下。 Function Decrypt-Asymme
通过问题Is it possible to use the Grails Jasypt plugin outside the GORM layer for simple String encrypti
我需要解密/加密我的域类中的几列,并且正在寻找有关如何做的信息。我已经找到了jasypt加密插件,但不幸的是它似乎与Grails 2.4不兼容。 我可能可以将一些东西拼凑在一起,但是想要确保Im遵循最
我需要有关声音文件加密/解密的帮助。我想在存储这个声音文件时加密一个声音文件,并在播放这个文件时解密它。我阅读了有关 java 中的加密/解密以及 java 中可用于此的大量示例代码。但这些程序不适用
我很感兴趣是否可以使用 Excel Visual Basic 和某些加密服务提供程序进行字符串加密/解密。 我找到了一个演练 Encrypting and Decrypting Strings in
我们正在使用加密/解密和UIIMAGE。如果我们在不保存到iphone画廊的情况下进行加密和解密以及UIIMAge,则可以正常工作,但是,如果我们进行加密,保存到画廊,将(加密的图像)加载到应用程序中
我正在做一个像这样的简单程序: package rsaexample; import java.io.*; import java.math.BigInteger; import java.secur
我发现这段代码返回给定字符串的校验和。 public static String getChecksum(String md5) { int counter = 0; while (c
我在 Java SE 和 Android 项目上使用相同的代码。在 Java 和 Android 中运行的应用程序连接到相同的 MQTT 代理并交换消息。消息使用 AES 进行加密/解密。我对 Jav
我想在 openssl/libcrypto 中使用 RSA 加密/解密一个长文件(我知道 AES 更好,但这只是为了比较)。我将输入文件分成大小为 numBlocks = inputFileLengt
我是一名优秀的程序员,十分优秀!