Skip to content

Instantly share code, notes, and snippets.

View DiegoQueiroz's full-sized avatar

Diego Queiroz DiegoQueiroz

  • São Paulo, SP, Brazil
View GitHub Profile
@DiegoQueiroz
DiegoQueiroz / GeraDigitosAleatorios.cs
Last active July 22, 2020 21:17
Arruma identação
using System;
using System.Text;
using System.Security.Cryptography;
public class Program {
public static void Main() {
Console.WriteLine(GeraDigitosAleatorios(8));
}
Imports System.Text
Imports System.Security.Cryptography
Module VBModule
Sub Main()
Console.WriteLine(GeraDigitosAleatorios(8))
End Sub
Function GeraDigitosAleatorios(ByVal tamanho As Integer) As String
Attribute VB_Name = "GeraDigitosAleatorios"
Option Explicit
Private Declare Function BCryptGenRandom Lib "bcrypt.dll" (ByVal hAlgorithm As Long, ByRef pbBuffer As Long, ByVal cbBuffer As Long, ByVal dwFlags As Long) As Long
Const BCRYPT_USE_SYSTEM_PREFERRED_RNG = &H2
Const STATUS_SUCCESS = &H0
Public Function GeraDigitosAleatorios(ByVal tamanho As Integer) As String
Const ERRO_GERACAO_SEQUENCIA_NUMERO = vbObjectError + 1
uses
Windows, SysUtils;
function GeraDigitosAleatorios(tamanho: Integer): String;
type
TBCryptGenRandom = function(hAlgorithm: THandle; pbBuffer: PUCHAR;
cbBuffer, dwFlags: ULONG): ULONG; stdcall;
const
bcryptdll = 'bcrypt.dll';
STATUS_SUCCESS = $00000000;